当前位置:Gxlcms > html代码 > 背景图片如果小于页面高度时,背景图片固定这个样式怎么写。_html/css_WEB-ITnose

背景图片如果小于页面高度时,背景图片固定这个样式怎么写。_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:36人阅读

背景图片高度是1400像素,网页高度是1900像素,到浏览到第三屏时背景图片固定。这个怎么写,这问题不太好描述,不知道能不能看明白。


回复讨论(解决方案)

用jquery scroll()来侦测是否浏览到第三屏,然后添加一个class,使得background-position, fixed.

jQuery(window).scroll(function(){    if(jQuery(window).scrollTop() > 1399){        jQuery('html').addClass('scrolled');    }else{        jQuery('html').removeClass('scrolled');    }});

html {    background:url(image.jpg);    background-repeat: no-repeat;    background-position: top left;}html.scrolled {    background-attachment:fixed;    background-position: bottom left;}

算是笨方法 你参考

无标题文档

人气教程排行