JS设置了元素的高度,但是在火狐浏览器上面不生效,为什么?

JavaScript011

JS设置了元素的高度,但是在火狐浏览器上面不生效,为什么?,第1张

火狐浏览器默认把可视区域的高度设为0,这样的话,$(window).height()就等于0了。在css的开头位置添加下面一行,即可兼容所有浏览器:html, body {width:100%height:100%}

你好!!

你这是要修改样式的意思吧,是想通过javascript来控制样式么?

可以直接为元素设置style来达到你想要的效果。

//首先<div class="list_top">增加一个id标识,改为<div id="listTop" class="list_top">

<script>

        //在这里配置你的内容,对照你自己要的数值就好了

        var config={

         "_width":"960px",

         "_height":"60px",

         "_background":"#faa",

         "_li_width":"",

         "_li_height":"",

         "_a_color":"yellow"

        }

        //初始化函数,将配置的数值,分别设置到元素中

        function init(config){

         var lstTop = document.getElementById("listTop")

         lstTop.style.width = config["_width"]?config["_width"]:lstTop.style.width

         lstTop.style.height= config["_height"]?config["_height"]:lstTop.style.height

         lstTop.style.background= config["_background"]?config["_background"]:lstTop.style.background

        

         var hot = document.getElementById("hottitle")

         hot.style.width = config["_width"]?config["_width"]:hot.style.width

         hot.style.height= config["_height"]?config["_height"]:hot.style.height

        

         var ul = document.getElementById("ulid")

         ul.style.width = config["_width"]?config["_width"]:ul.style.width

         ul.style.height= config["_height"]?config["_height"]:ul.style.height

        

         var lis = ul.getElementsByTagName("li")

         for(var i=0i<lis.lengthi++){

         lis[i].style.width = config["_li_width"]?config["_li_width"]:lis[i].style.width

         lis[i].style.height= config["_li_width"]?config["_li_width"]:lis[i].style.height

         var a = lis[i].getElementsByTagName("a")

         a[0].style.color = config["_a_color"]?config["_a_color"]:a[0].style.color

         }

        }

        window.onload = function(){

         init(config)

        }

</script>

swiper.js 没有限制slider的高度,因为考虑到图片的不规则性,限制了高度,对于一些过大或者过小的图片会造成失真,你可以通过自己设置slider的高度,通过overflow:hidden来避免失真。