[英]transition not working on 1st scroll
I have script for reduce height of logo when scrolling but I scroll for the first time transition for the logo not working. 我有用于减少滚动时徽标高度的脚本,但是第一次滚动时徽标无法工作。 Everything else work fine.
其他一切正常。 From the second time logo transition also start to work.
从第二次徽标过渡也开始起作用。 I dont know what is the wrong.
我不知道怎么了。 Please help I really appreciate it.
请帮助我,我真的很感激。
$(window).scroll(function() {
ypos = window.pageYOffset;
var logo = document.getElementById('logo');
var nav = document.getElementById('main_nav');
var sm = document.getElementById('sm');
var mm = document.getElementById('mm');
var but = document.getElementById('tp-button');
var but2 = document.getElementById('tp-button2');
if (ypos > 1) {
logo.style.height = '70px'
nav.style.height = '70px'
sm.style.marginTop = '13px'
mm.style.marginTop = '5px'
} else {
logo.style.height = '107px'
nav.style.height = '107px'
sm.style.marginTop = '30px'
mm.style.marginTop = '20px'
}
});
http://jsfiddle.net/ty2fjhhr/ here is the link to fiddle http://jsfiddle.net/ty2fjhhr/这是小提琴的链接
You need to change your javascript function 您需要更改您的JavaScript函数
Demo Link : http://jsfiddle.net/ty2fjhhr/3/ 演示链接: http : //jsfiddle.net/ty2fjhhr/3/
$(document).ready(function(){
function myCustomFunction()
{
var ypos = window.pageYOffset;
var logo = document.getElementById('logo');
var nav = document.getElementById('main_nav');
var sm = document.getElementById('sm');
var mm = document.getElementById('mm');
var but = document.getElementById('tp-button');
var but2 = document.getElementById('tp-button2');
if (ypos > 1) {
logo.style.height = '70px'
nav.style.height = '70px'
sm.style.marginTop = '13px'
mm.style.marginTop = '5px'
} else {
logo.style.height = '107px'
nav.style.height = '107px'
sm.style.marginTop = '30px'
mm.style.marginTop = '20px'
}
}
myCustomFunction();
$(window).scroll(function() {
myCustomFunction();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.