关于跳转的问题
chrome里点击两三次才会跳转,火狐里怎么点都没反应, 代码就是和老师写的一样的,控制台也测试过document.body.scrollTop值已经ok,就是无法跳转。
把onclick改成onmoouseover效果就是好的
//获取元素 var getElem = function(selector) { return document.querySelector(selector); } var getAllElem = function(selector) { return document.querySelectorAll(selector); } //获取元素样式 var getCls = function(element) { return element.getAttribute('class'); } //设置元素样式 var setCls = function(element, cls) { return element.setAttribute('class', cls); } //为元素添加样式 var addCls = function(element, cls) { var baseCls = getCls(element); if(baseCls.indexOf(cls) === -1) { setCls(element, baseCls + " " + cls) } } //为元素删除样式 var delCls = function(element, cls) { var baseCls = getCls(element); if(baseCls.indexOf(cls) != -1) { setCls(element, baseCls.split(cls).join(" ").replace((/\s+/g), " ")); } } //初始化init样式 var screenAnimateElements = { '.screen-1': [ '.screen-1_heading', '.screen-1_phone', '.screen-1_shadow', ], '.screen-2': [ '.screen-2_heading', '.screen-2_phone', '.screen-2_subheading', '.screen-2_point', '.screen-2_point_i_1', '.screen-2_point_i_2', '.screen-2_point_i_3', ], '.screen-3': [ '.screen-3_heading', '.screen-3_phone', '.screen-3_subheading', '.screen-3_features', ], '.screen-4': [ '.screen-4_heading', '.screen-4_subheading', '.screen-4_type_item_i_1', '.screen-4_type_item_i_2', '.screen-4_type_item_i_3', '.screen-4_type_item_i_4', ], '.screen-5': [ '.screen-5_heading', '.screen-5_subheading', ], } //设置屏内元素为初始状态 var setScreenAnimateInit = function(screenCls) { var screen = document.querySelector(screenCls); //获取当屏的元素 var animateElements = screenAnimateElements[screenCls]; //需要设置动画的元素 for(var i = 0; i < animateElements.length; i++) { var element = document.querySelector(animateElements[i]); var baseCls = element.getAttribute("class"); element.setAttribute("class", baseCls + " " + animateElements[i].substr(1) + "_animate_init"); } } //设置播放屏内元素动画 var playScreenAnimateDone = function(screenCls) { var screen = document.querySelector(screenCls); //获取当屏的元素 var animateElements = screenAnimateElements[screenCls]; //需要设置动画的元素 for(var i = 0; i < animateElements.length; i++) { var element = document.querySelector(animateElements[i]); var baseCls = element.getAttribute("class"); element.setAttribute("class", baseCls.replace("animate_init", "animate_done")); } } window.onload = function() { for(k in screenAnimateElements) { setScreenAnimateInit(k); } } //滚动到哪里就播放到哪里 window.onscroll = function() { var top=null; if(document.body.scrollTop){ top=document.body.scrollTop; } else{ top=document.documentElement.scrollTop; }; if(top > 80) { addCls(getElem(".header"), "header_status_black"); addCls(getElem(".outline"), "outline_status_in"); } else { delCls(getElem(".header"), "header_status_black"); delCls(getElem(".outline"), "outline_status_in"); } if(top > 1) { playScreenAnimateDone('.screen-1') } if(top > (800 * 1 - 100)) { playScreenAnimateDone('.screen-2') } if(top > (800 * 2 - 100)) { playScreenAnimateDone('.screen-3') } if(top > (800 * 3 - 100)) { playScreenAnimateDone('.screen-4') } if(top > (800 * 4 - 100)) { playScreenAnimateDone('.screen-5') } } //双向定位 var navItems = getAllElem(".header_nav-item"); var outlineItems = getAllElem(".outline_item"); var setNavJump = function(i, lib) { var item = lib[i]; item.onmouseover = function() { document.body.scrollTop = i*800; document.documentElement.scrollTop=i*800; } } for(var i = 0; i < navItems.length; i++) { setNavJump(i, navItems); } for(var i = 0; i < outlineItems.length; i++) { setNavJump(i, outlineItems); }
109
收起
正在回答 回答被采纳积分+1
3回答
HTML5与CSS3实现动态网页 2018
- 参与学习 1887 人
- 提交作业 4643 份
- 解答问题 5760 个
有HTML和CSS基础,却不知道如何进阶?本路径带你通过系统学习,完成从“会做网页”到“做出好的动态网页”的蜕变,迈出成为前端工程师的第一步。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星