#StackBounty: #javascript #html #css #css-animations #onscroll How to get exact scroll position when animating elements onScroll

Bounty: 100

I am trying to animate elements while scrolling based on the elements progress through the scene. I am running into the issue of the browser returning intermittent scroll positions making it difficult to be exact when starting and stopping element animation.

Minimal example:

Fiddle Fiddle Demo

const tweens = document.querySelectorAll('.tween');
const trigger = document.querySelector('.start');
const triggerRect = trigger.getBoundingClientRect();

let yScroll = window.scrollY;
let yCurrent = yScroll;
let AF = null;

const start = triggerRect.top - yScroll - 200;
const end = start + 400;

const updateScroll = () => {
    yScroll = window.scrollY;
  startAnimation();
}

const startAnimation = () => {
  if(!AF) AF = requestAnimationFrame(animate)
}

const cancelAnimation = () => {
  yCurrent = yScroll;
  cancelAnimationFrame(AF);
  AF = null;
}

const animate = () => {
  if(yCurrent === yScroll) cancelAnimation();
  else {
    updateElements();
    yCurrent = yScroll;
    AF = requestAnimationFrame(animate);
  }
}

const updateElements = () => {
  const pos = yCurrent - start;
  if(inScene()){
    tweens[0].style.transform = `translateX(${pos}px)`;
    tweens[1].style.transform = `translateY(${pos}px)`;
  }
}

const inScene = () => {
  return start <= yCurrent && end >= yCurrent ? true : false;
};


window.addEventListener('scroll', updateScroll);
.wrapper{
  position:relative;
  margin: 100vh 20px;
  background: rgb(240,240,240);
  height: 900px;
  border: 1px solid red;
}

.line{
  position:absolute;
  left: 0;
  width: 100%;
  height: 1px;
  background: red;
}

.start{
  top: 200px;
}

.end{
  bottom: 200px;
}

.tween{
  position:absolute;
  top:200px;
  width: 100px;
  height: 100px;
  background: blue;
}

.left{
  left: 0;
}

.right{
  right: 0;
}
<h1>Scroll Down</h1>
<div class="wrapper">
  <div class="line start trigger"></div>
  <div class="line end"></div>
  <div class="tween left"></div>
  <div class="tween right"></div>
</div>

As you can see the elements are supposed to stop on the lines but when you scroll they never really do. And the faster you scroll the worse it becomes.

So is there a technique to either return the correct scroll position or somehow debounce the elements so then can reach the full range when scrolling instead of constantly coming up short of their intended position?

I know this is possible because scrolling libraries like ScrollMagic do a pretty good job of handling this but I don’t really want to deconstruct then entire ScrollMagic framework to find out how they achieve it. I would use the ScrollMagic framework itself but I am trying to have a momentum style scrolling container wrapping the page and translating it on scroll along with elements inside this container and using ScrollMagic it is pretty buggy. So I figured I would post the question here and see if anyone had any experience or insight on the situation.

Any guidance would be appreciated as I have been mulling over this for a while.


Get this bounty!!!

#StackBounty: #jquery #html #fancybox #fancybox-2 Fancybox 2.1 loading AJAX template leaving large gap at the top, but this problem doe…

Bounty: 100

On my eCommerce website, I am using Fancybox to load the shopping cart upon someone clicking the add to cart button. This works without issues. The page does not jump to the top in the background, and the modal cart window is always displayed in the center, or at the top when the page height is not enough. There is only ever a Top: 20px on this cart modal and you cannot scroll up any further.

Here is the code I’m using for the Fancybox modal shopping cart (which works perfectly):

(function ($, F) {

    // Opening animation - fly from the top
    F.transitions.dropIn = function() {

        var endPos = F._getPosition(true);

        endPos.top = (parseInt(endPos.top, 10) - 50) + 'px';
        endPos.opacity = 0;

        F.wrap.css(endPos).show().animate({
            top: '+=50px',
            opacity: 1
        }, {
            duration: F.current.openSpeed,
            complete: F._afterZoomIn
        });
    };

    // Closing animation - fly to the top
    F.transitions.dropOut = function() {
        F.wrap.removeClass('fancybox-opened').animate({
            top: '-=50px',
            opacity: 0
        }, {
            duration: F.current.closeSpeed,
            complete: F._afterZoomOut
        });
    };

}(jQuery, jQuery.fancybox));

$(".cart-button").fancybox({
maxWidth    : 700,
maxHeight   : 600,
fitToView   : false,
width       : '100%',
height      : '70%',
autoSize    : false,
autoDimensions: false,
autoCenter : true,
closeClick  : false,
openMethod:'dropIn',
openSpeed:200,
closeMethod:'dropOut',
closeSpeed:200,
helpers : {
  overlay : {
      locked : true // try changing to true and scrolling around the page
  }
}
});

Now I need to use Fancybox in another way which involves loading a page template via AJAX when a button is clicked. Unlike the modal cart, this page template is long enough that it will always exceed the visible page height. The issue is that it keeps assigning Top: 632px (varies) to the Fancybox modal, whichthen leaves a large empty spot at the top. That said, it does display the Fancybox modal at the top of the screen with a 20px space at the top (like the cart), however, the user can keep scrolling up to view the additional 600+px of empty space a the top (the dark overlay is seen in this space). This problem seems to only happen on Desktop, as it behaves just fine on mobile.

Here is the code I’m using for loading the template via Fancybox:

$(document).ready(function() {
  $(".trees-modal-button").click(function(e) {
    e.preventDefault();
    $.fancybox({
        maxWidth    : 700,
        maxHeight   : 600,
        fitToView   : false,
        width       : '100%',
        height      : '70%',
        autoSize    : false,
        autoDimensions: false,
        autoCenter : true,
        closeClick  : false,
        openMethod:'dropIn',
        openSpeed:200,
        closeMethod:'dropOut',
        closeSpeed:200,
        helpers : {
          overlay : {
              locked : true // try changing to true and scrolling around the page
          }
        },
        content: `<div class="loading-directive" style="display: block; position: relative; margin: 
        auto;">
         <div class="loader">
           <svg class="circular">
            <circle class="path" cx="32" cy="32" r="30" fill="none" stroke-width="4">
            </circle>
           </svg>
         </div>
       </div>`
      });

    $.get('/pages/tree-planting-temp-noindex', null, function(data) {
        $.fancybox({
          maxWidth  : 700,
          maxHeight : 600,
          fitToView : false,
          width     : '100%',
          height        : '70%',
          autoSize  : false,
          autoDimensions: false,
          autoCenter : true,
          closeClick    : false,
          openMethod:'dropIn',
          openSpeed:200,
          closeMethod:'dropOut',
          closeSpeed:200,
          content: data,
          helpers : {
            overlay : {
                locked : true // try changing to true and scrolling around the page
            }
          }
        });
      }
    )
  })
}) 

It first opens the modal popup with a loading animation, and then displays the template when ready. I used the same Fancybox variables as the shopping cart, so I’m not sure what the issue is.

Worth mentioning that if I force the CSS to be Top: 20px to override the large value generated by the Fancybox modal, the modal will just pop to the very top of the page, and then you have to scroll up to see top of the modal.

Your help is most appreciated.


Get this bounty!!!

#StackBounty: #html #css #height How to remove random jump on image when zooming in on it

Bounty: 200

when I press on an image its supposed to blow up into a larger picture. However, I changed the size so the image isn’t fully touching the bottom and top of the screen by changing the height to 90vh. However, now when I press the image you can see it shift up that 10vh before expanding the image. Can someone help me remove that jump?

https://darrientu.com/

    .pswp {  height:100vh !important;
margin:auto!important;top:0 !important;
    bottom:0 !important;
}

.pswp__scroll-wrap {
height:90vh !important;margin:auto!important;top:0 !important;
    bottom:0 !important;
}


Get this bounty!!!

#StackBounty: #python #html #jupyter-notebook #ipywidgets #nbconvert Output widget appears outside tab widget when using nbconvert on j…

Bounty: 50

I created a notebook which should display plots in a tab widget. As far as I understand, to include something like plots in the tab widget, I need to wrap it in the output widget. In the notebook itself it works but when I convert it to html via nbconvert it produces the wrong output.

Widgets like sliders, buttons or text appear within the tab widget where they should, but when I use the output widget to catch the plot (or even some text from a print() function) it appears before the tab environment which itself is then empty.

This is the how it shoud look with one plot per tab (works in the notebook):
Plots in tabs within notebook

And this is how it looks after nbconvert (in html). The plots appear before the tab envorinment:
Plots before tabs in html

Please note that nbconvert includes other widgets fine and also tabs with other content.

This is the used code:

# Import libraries
import pandas as pd
import matplotlib.pyplot as plt
import ipywidgets as widgets
import numpy as np

# Generated data for plotting
data = pd.DataFrame()
for i in range(5):
    data[i] = np.random.normal(size = 50)

Now this part works in the notebook but not in the html, but as you will see it seems to be related to the output widget, as I does not work with plots or printed text.

# This does not work with plots
children = []
for i in range(data.shape[1]):
    out = widgets.Output()
    with out:
        fig, axes = plt.subplots()
        data[i].hist(ax = axes)
        plt.show()
    children.append(out)
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
    tab.set_title(i, "Plot " + str(i))
tab

# And this does not work with printed output
children = []
for i in range(5):
    out = widgets.Output()
    with out:
        print("This is text", i)
    children.append(out)
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
    tab.set_title(i, "Text " + str(i))
tab

However, if I use a different widget type (e.g. Text) it is displayed correctly in the notebook and the html output from nbconvert.

# This works with the Text widget
children = []
for i in range(5):
    out = widgets.Text(description="P"+str(i))
    children.append(out)
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
    tab.set_title(i, "Text " + str(i))
tab

So, is there something I can change to make this actually work? What I need in the end is a way to display N plots in N tabs…


Get this bounty!!!

#StackBounty: #html #focus #input-field Clicking on the padding of an input field sets the cursor at the beginning of the line, not at …

Bounty: 100

On a HTML input field that has some padding defined, clicking on the padding area sets the cursor at the beginning of the line and not at the end.
Why is that happening? What would be a use case for this behaviour?
Any idea on how to prevent this and move always the cursor at the end of the line?

enter image description here

<input style="padding:25px;font-size:25px" value="hello" />

https://jsfiddle.net/sf4x3uzL/1


Get this bounty!!!

#StackBounty: #html #css #html-table #css-position #absolute Table with fixed position of columns without setting height and width of t…

Bounty: 150

I have a table with fixed first three columns. My first three columns are fixed. What I want is that the rest columns should calculate their height and width automatically, based on their content.

So my CSS looks like this:

.outer {
  position:relative;
  background-color: hotpink;
}
.inner {
  overflow-x:scroll;
  overflow-y: visible;
  width: calc(100% - 1500px);
  margin-left: 25.3em;
  background-color: greenyellow;
}

table {
  table-layout: fixed;
  width: 100%;
}

td, th {
  vertical-align: top;
  border-top: 1px solid #ccc;
  padding: 0.8em;
  width:6em;
  height: 4em;
}

.col1 {
  position:absolute;
  left: 0em;
  width: 6em;
}

.col2 {
  position:absolute;
  left: 6em;
  width: 6em;
}

.col3 {
  position:absolute;
  left: 12em;
  width: 6em;
}

This is HTML of table:

<div class="outer">
    <div class="inner">
      <table>
        <tr>
          <th class="col1">Header A1</th>
          <th class="col2">Header A</th>
          <th class="col3">Header A</th>

          <td>col 2 - A (WITH LONGER CONTENT)</td>
          <td>col 3 - A</td>
          <td>col 4 - A</td>
          <td>col 5 - A</td>
        </tr>
        <tr>
          <th class="col1">This row should be empty</th>
          <th class="col2">This row should be empty</th>
          <th class="col3">This row should be empty</th>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <th class="col1">Header B</th>
          <th class="col2">Header B</th>
          <th class="col3">Header B</th>

          <td>col 2 - B 123345</td>
          <td>col 3 - B</td>
          <td>col 4 - B</td>
          <td>col 5 - B</td>

        </tr>
        <tr>
          <th class="col1">Header C</th>
          <th class="col2">Header C</th>
          <th class="col3">Header C</th>

          <td>col 2 - C/td>
          <td>col 3 - C</td>
          <td>col 4 - C</td>
          <td>col 5 - C</td>
        </tr>
      </table>
    </div>
  </div>

Is it possible to avoid setting width and height in td, th?

I mean to avoid this hardcoded values of height and width:

td, th {
  ...
  width:6em;
  height: 4em;
}

Is it possible to do just with plain CSS without JavaScript? If it is not possible to implement with this solution, it would be really great to see another approach.


Get this bounty!!!

#StackBounty: #javascript #html #iframe #cross-domain Refresh html frames for cross-domain sites out of my control

Bounty: 50

This may be a bit of an x y problem, so I’ll give a small bit of background to start with. I am attempting to make a simple dashboard which loads a number of different sites and which cycles between them. To do this I have set up a simple local server along with a html page which gets populated with the different sites in distict frames and then cycles between them by hiding/showing each one in turn. In simple terms, the page looks like this:

<html>
<head></head>
<body>
http://www.example1.com
http://www.example2.com
http://www.example2.com
</body>
</html>

Now, what I would like to do is be able to force a reload of each frame so that the data is up to date. For most sites I can do this with:

document.getElementById['iframe.src'] = document.getElementById['iframe.src']

However, for sites where content changes aren’t reflected in the URL, this won’t work and will instead ‘refresh’ the page back to the home page. What I want to do is esentially submit an F5 sort of refresh direct to the frame or use:

document.getElementById("iframe_id").contentWindow.location.href

or

document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);

But, due to CORS, I can’t do this. Considering the sites are external sites that I am viewing and have no control over I’m struggling to come up with a way to get around this issue. Is there something pretty obvious that I am missing?


Get this bounty!!!

#StackBounty: #javascript #jquery #html #css Element from fixed to relative on scroll

Bounty: 100

I have made a wrapper in which I have animated the same effect as Apple on their Airpods Pro page. It’s basically a video, when I scroll the video plays bit by bit. The video’s position is fixed so the text nicely scrolls over it. However, the text is only visible when between the offset of a specific division (text-display).

That part works fine. Now I want that when the user has scrolled to the end of the video, and thus the animation is finished, that the video-effect-wrapper goes from a fixed position to a relative position. So that website will scroll it’s content normally after the video-animation.

JSFIDDLE CODE + DEMO

This is an example of what I already tried:

        //If video-animation ended: Make position of video-wrapper relative to continue scrolling
        if ($(window).scrollTop() >= $("#video-effect-wrapper").height()) {
            $(video).css("position", "relative");
            $("#video-effect-wrapper .text").css("display", "none");
        }

This kind of works… But is everything except smooth. And it also needs to be possible to reverse scroll the webpage backwards.

Problems I encountered when trying to fix this problem:

  • The scrolling, and transition from fixed to relative needs to feel natural and smooth
  • The wrapper itself isn’t fixed and contains .text elements, the video is fixed so the .text elements can go over the video element (creating the effect). These .text elements cause problems trying to find a solution


Get this bounty!!!

#StackBounty: #html #css #asp.net-mvc #bootstrap-4 How to change the position of Bootstrap Navigation Bar parent menu item icon at mobi…

Bounty: 50

I am looking for a way to change the position of the bootstrap navigation menu bar parent menu icon, when open in mobile view.

Currently the menu header contains right-arrow-down icon at the end of header name like below.

enter image description here

My requirement is to convert the highlighted right-arrow-down icon to left-arrow icon and change the icon position to start of parent
header menu text and also to change the background color (gray) of parent menu item on mouse hover like below.

enter image description here

below is the navigation menu bar HTML code:

<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav">
    <li class="nav-item" style="background-color: #f5f5f5; height:33px; padding-top:8px;">
        <label class="label d-md-block d-lg-none">Welcome, abc</label>
    </li>
    <li class="nav-item dropdown">
        <a href="#" class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">ACCOUNTS</a>
        <div class="dropdown-menu">
            <a class="dropdown-item"><span class="k-icon k-i-plus"></span>New Prospect</a>
            <a class="dropdown-item">Accounts</a>
            <a class="dropdown-item">Prospects</a>
            <a class="dropdown-item">Account Reports</a>
            <a class="dropdown-item">My Account Reports</a>
            <a class="dropdown-item"><span class="k-icon k-i-star"></span> Favorites</a>
        </div>
    </li>
    <li class="nav-item dropdown">
        <a href="#" class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">CONTACTS</a>
        <div class="dropdown-menu">
            <a class="dropdown-item">Item 1</a>
            <a class="dropdown-item"><span class="k-icon k-i-star"></span> Favorites</a>
        </div>
    </li>
    <li class="nav-item dropdown">
        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">LEADS</a>
        <div class="dropdown-menu">         
            <a class="dropdown-item"><span class="k-icon k-i-star"></span> Favorites</a>
        </div>
    </li>
    <li class="nav-item dropdown">
        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">OPPORTUNITIES</a>
        <div class="dropdown-menu">
            <a class="dropdown-item">Item 1</a>
        </div>
    </li>
    <li class="nav-item dropdown">
        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">ACTIVITIES</a>
        <div class="dropdown-menu">
            <a class="dropdown-item">Item 1</a>
        </div>
    </li>
</ul>
</div>

It might required to override the existing bootstrap classes to acheive this but I am not sure which class will work for me.
I have tried to look for the ways to acheive this using Bootstrap CSS online but not found any example similar to my requirement. Appreciate your help.


Get this bounty!!!

#StackBounty: #htaccess #html #php #web-development #webserver Use .htaccess/SSH/Cpanel to prevent a specific part of a specific PHP sc…

Bounty: 350

I have a website built with MediaWiki CMS which I host on a CentOS based Apache “shared server environment” (SiteGround) in which I can partially control Apache by:

  • .htaccess files
  • SSH
  • Some Cpanel tools

Background to understand my problem

My website contains a ContactPage contact form in which the subject field is hardcoded into the form wrapper via PHP;
This is odd, because all other fields aren’t hardcoded like this and are actually optional and injected into the wrapper from the form’s default template which I pasted into the main customization file of the CMS (LocalSettings.php);
I also added a select list field myself, directing potential customers to send me contextualized job inquiry messages only.
All of the aforementioned optional fields are HTMLForm template-engine fields.

If someone wants to remove the subject field from backend (from the PHP code by which it is hardcoded) from whatever reason, it would be a logistical pain, because, for example, after every automatic upgrade, it will have to be removed again, probably manually, from ContactPage extension relevant PHP source code (unlike all other fields which are optional from the very stable file LocalSettings.php).

My problem

I want to remove the aforementioned subject field and the only very stable ways I have with the current architecture of MediaWiki, are CSS and JS;
But this is problematic because a user can easily turn off both (most users won’t do that, but still).
I want to remove the field because I have other custom fields such a select list that direct a customer to send me messages in the context of jobs only (I don’t want to get any other kind of messages from surfers in that particular site).

My question

How to prevent parsing of a should-be-parsed HTML element from server (Apache)?

Is there any “nasty trick” with .htaccess, SSH or Cpanel to prevent the parsing of the should-be-parsed subject field by some criteria (say, its HTML attribute or CSS class or whatever other applicable criteria)?


Get this bounty!!!