简体   繁体   English

视差滚动中的实时调整大小

[英]real-time resizing in Parallax Scrolling

I was using the stellar.js in my project. 我在项目中使用了stellar.js
There is a question - under the "realtime resize" requirement( do not reload page ). 有一个问题-在“实时调整大小”要求下( 请勿重新加载页面 )。 when I using the resize function to calculate the new position LEFT in horizontal scrolling below: 当我在下面的水平滚动中使用调整大小功能计算新位置LEFT时:

$(window).resize(function(){
    var newPos = element.position().left*100; //Get NEW Position ...
    element.css("left", newPos);        //It's not working ...
});

the elements with "data-stellar-ratio" will not be overwrite. 具有“ data-stellar-ratio”的元素将不会被覆盖。
How do i do to slove this problem ? 我该如何解决这个问题?

Thanks for your help. 谢谢你的帮助。

Under the requirement below 根据以下要求
-> When resizing browser then recalculate the element position in real-time ( NO Reload page ) ->调整浏览器大小时,然后实时重新计算元素位置(“不重新加载”页面)
-> So, I will recalculate position and overwrite new position to element. ->因此,我将重新计算位置并将新位置覆盖到元素。
-> But, the element which use data-stellar-ratio attribute can not be overwrite new position .(example in comment) ->但是,使用data-stellar-ratio属性的元素不能覆盖新位置 。(注释示例)
here is my problem. 这是我的问题。 thank you for your help again. 再次感谢您的帮助。

Your question is very unclear. 您的问题还不清楚。 But, if you wish to change the data-stellar-ratio attribute, you would do it like this. 但是,如果您希望更改data-stellar-ratio属性,则可以这样做。

element.attr('data-stellar-ratio', 2);

element must be a jQuery object. element必须是jQuery对象。

To you refer 给你参考

_repositionElements: function() in stellar.js _repositionElements:stellar.js中的function()

if (this.options.horizontalScrolling) {
 var bSize = this.options.refWidth,bResize = $(window).width(),bRatio = this.options.formula(bResize, bSize);

newPositionLeft = (scrollLeft + particle.horizontalOffset + this.viewportOffsetLeft + particle.startingPositionLeft - particle.startingOffsetLeft + particle.parentOffsetLeft) * -(particle.stellarRatio + fixedRatioOffset - 1) + particle.startingPositionLeft; 

newPositionLeft *= bRatio;   //all element reposition in here

newOffsetLeft = newPositionLeft - particle.startingPositionLeft + particle.startingOffsetLeft;

}

bSize = resizing browser before bSize =调整浏览器大小之前
bResize = resizing browser after bResize =之后调整浏览器大小
bRatio = resize ratio bRatio =调整大小比例
newPositionLfet = all element position left newPositionLfet =剩余所有元素位置

newPositionTop = the same to newPositionLeft newPositionTop =与newPositionLeft相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM