css文件内使用js
这个是我的一个同事使用的方法,之前自己没有用过,看了他写的代码,我震惊了一下,原来css内部竟然也可以使用javascript代码,真实长见识了,学习了…… 下面是其中的一段代码,考了过来,留着以后自己查看使用。 #carousel_photo_container #pre { width: expression(document.getElementById("carousel_photo").width/2 < 300 ? document.getElementById("carousel_photo").width/2 : "300px"); left: expression(document.getElementById("carousel_photo").width/2 < 300 ? 87+300-document.getElementById("carousel_photo").width/2 : "87px"); } #carousel_photo_container #next { width: expression(document.getElementById("carousel_photo").width/2 < 300 ? document.getElementById("carousel_photo").width/2 :"300px"); right: expression(document.getElementById("carousel_photo").width/2 < 300 ? 87+300-document.getElementById("carousel_photo").width/2 :"87px"); background-image: url(../images/cover.gif); } #carousel_photo { padding: 5px; border: 1px solid #990033; max-width:600px; height:auto; _width:expression(this.width > 600 ? "600px" : this.width); }
这单代码主要作用是根据图片的宽度来实现显示时候图片的宽度!