我有一个脚本可以检测某人使用的浏览器(和版本),我想对其进行设置,以便对于某些浏览器,div 类在悬停时获得动画。我想用 jQuery 来做这件事,但我愿意接受任何东西。
我对 JavaScript 的想法是这样的......
if (browser == IE || browser < Firefox 4) {
// somehow animate a div class on hover (could be id-based too)
} else {
// do nothing
}
我为此设置的 CSS 是这样的
.item {
height: 100px;
width: 100px;
/* css3 */
transition: height .5s, width .5s;
-moz-transition: height .5s, width .5s;
-webkit-transition: height .5s, width .5s;
}
.item:hover {
height: 200px;
width: 200px;
}
然后 HTML 是(显然)
<div class="item" id="item">
<p>Content here</p>
</div><!-- end item -->
目的是为旧版浏览器修复 CSS3。在我看来,过渡是 CSS3 最好的东西之一,令我恼火的是 IE9 不支持它们。
最佳答案
除此之外,使用像 Modernizr 库这样的东西怎么样?
Modernizr adds classes to the element which allow you to target specific browser functionality in your stylesheet. You don't actually need to write any Javascript to use it.
然后你可以做这样的事情:
.multiplebgs div p {
/* properties for browsers that
support multiple backgrounds */
}
.no-multiplebgs div p {
/* optional fallback properties
for browsers that don't */
}
关于javascript - 如果浏览器,使用 Javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5780449/