javascript - 在jquery中选择背景图像“ONLY”的方法?
问题描述
我在 jQuery 中设置为“仅”在背景图像上提供 scale 属性,但 div 自身不断变大。像这样:
这就是我在 jQuery 和 HTML 中设置的方式。
var bg = $('.news_box_long').css('background-image', 'img/img_09.jpg')
$('.news_box_long').mouseenter(function(){
if(!$(bg).is(':animated')) {
$(this).css({'transform': 'scale('+ 1.1 +')'})
}
})
<div class="news_box_long background" style="background-image: url(img/img_09.jpg)">
</div>
解决方案
你不需要 jQuery。CSS就足够了
.news_box_long {
height: 200px;
}
.background {
background: 50% 50%/100% none no-repeat;
transition: background 0.5s;
}
.background:hover {
background-size: 150%;
}
<div class="news_box_long background" style="background-image:url(https://i.pinimg.com/originals/9f/1f/f5/9f1ff5f730db75ce458ee2890b8e6197.jpg)">
</div>
推荐阅读
- java - SPOJ 下一个回文(Java)
- react-native - 返回到 React-Native 中的上一个组件时调用函数
- sql - 从存储过程运行时,Ntile 函数没有均匀地划分组
- postgresql - 物化视图和简单视图如何与 postgresql 中的外部数据表 (fdt) 相关联?
- excel - 在单元格中设置字符串值并避免将其误解为美国日期
- database - 无法从 IDE 连接到 postgresql 数据库,而可能从 API
- android - NTFS 分区上的 Android Studio 构建错误
- wordpress - CPT 不使用存档-{post_type}.php
- octave - 八度,错误未定义变量,未将数据数组识别为函数的输入
- c# - ModelState 错误 - Newtonsoft.Json.JsonSerializationException:无法填充列表类型 System.Net.TrackingStringDictionary