gpt4 book ai didi

javascript - ScrollMagic 媒体查询?

转载 作者:行者123 更新时间:2023-11-27 23:31:52 24 4
gpt4 key购买 nike

我正在使用 ScrollMagic 插件,发现 here 。我在尝试跨多个屏幕尺寸固定对象时遇到问题。问题是我在引脚的“持续时间”属性中进行硬编码,但持续时间设置为像素。由于像素根据您使用的设备而不同,因此会导致问题。这是我当前的代码:

var controller = new ScrollMagic.Controller();

//Pen sticks to page (PATIENT-PAGE)
new ScrollMagic.Scene({
duration: 2300,
offset: 0
})
.setPin(".patient-pen")
.addTo(controller);

这实际上设置起来非常简单。现在,我真正想做的是这样的:

if(mobile == true) {
var myDuration == 500;
} else {
var myDuration == 2300;
}

new ScrollMagic.Scene({
duration: myDuration,
offset: 0
})
.setPin(".patient-pen")
.addTo(controller);

这个插件可以实现吗?是否有捷径可寻?我在文档中没有看到任何有关它的内容。

最佳答案

我刚刚这样做了,现在似乎可以正常工作了。

(function(){
var width = window.innerWidth,
height = window.innerHeight;
console.log( width + ' : ' + height );

if (width >= 768) {
//Pen sticks to page (HCP-PAGE)
new ScrollMagic.Scene({
// duration: 2400,
duration: 2400,
offset: 0
})
.setPin(".pen")
.addTo(controller);

//Pen sticks to page (PATIENT-PAGE)
new ScrollMagic.Scene({
duration: 2300,
offset: 0
})
.setPin(".patient-pen")
.addTo(controller);
} else if (width < 768) {
//Pen sticks to page (HCP-PAGE)
new ScrollMagic.Scene({
// duration: 2400,
duration: 1250,
offset: 0
})
.setPin(".pen")
.addTo(controller);

//Pen sticks to page (PATIENT-PAGE)
new ScrollMagic.Scene({
duration: 1250,
offset: 0
})
.setPin(".patient-pen")
.addTo(controller);

}

}());

关于javascript - ScrollMagic 媒体查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34498891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com