html鼠标移动到超链接上时,显示图片的效果怎么做的?

html-css011

html鼠标移动到超链接上时,显示图片的效果怎么做的?,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html,输入问题基础代码。

2、在index.html中的<script>标签中,输入js代码:

$('a').hover(function(){$('img').css('display','block')})

3、浏览器运行index.html页面,此时鼠标移动到超链接上,下面的图片自动显示了出来。

1、首先输入代码:

<div class="wrapper">

<div id="focus">

<ul>

<li><a href="http://www.lanrentuku.com/" target="_blank"><img src="img/01.jpg" alt="QQ商城焦点图效果下载" /></a></li>

2、然后输入代码:

<li><a href="http://www.lanrentuku.com/" target="_blank"><img src="img/02.jpg" alt="QQ商城焦点图效果教程" /></a></li>

<li><a href="http://www.lanrentuku.com/" target="_blank"><img src="img/03.jpg" alt="jquery商城焦点图效果" /></a></li>

<li><a href="http://www.lanrentuku.com/" target="_blank"><img src="img/04.jpg" alt="jquery商城焦点图代码" /></a></li>

3、然后再输入代码:

<li><a href="http://www.lanrentuku.com/" target="_blank"><img src="img/05.jpg" alt="jquery商城焦点图源码" /></a></li>

</ul>

</div>

</div><!-- wrapper end -->

</body>

4、然后就完成了。

background-image不支持CSS3 transition

background-image 不支持CSS3 transition ,而CSS3 gradient渐变作为背景图片存在的时候,下面的CSS设置是不会有过渡效果的。

.gradient {

background-image: linear-gradient(to right, olive, green)

transition: background-image 0.5s linear

}

.gradient:hover {

background-image: linear-gradient(to right, green, purple)

}

鼠标hover会发现渐变的变化是很唐突的,一点过渡效果也没有。

下面问题来了,如果我们希望实现渐变hover时候有过渡变化的效果,该如何实现呢?我这里罗列的几种可行的方法。

二、借助background-position实现渐变过渡

background-image 虽然不支持CSS3 transition 过渡,但是 background-position 支持啊,于是,通过控制背景位置,我们是可以实现渐变过渡效果的。

实现效果如下(鼠标hover):

相关代码如下:

.box {

max-width: 400px

height: 200px

background: linear-gradient(to right, olive, green, purple)

background-size: 200%

transition: background-position .5s

}

.box:hover {

background-position: 100% 0

}

三、借助background-color实现渐变过渡

background-image 虽然不支持CSS3 transition 过渡,但是 background-color 支持啊,于是,通过控制背景颜色,和一个颜色呈现技巧,我们也是可以实现渐变过渡效果的。

鼠标hover前后效果对比:

相关代码如下:

.box {

max-width: 400px

height: 200px

background: olive linear-gradient(to right, rgba(0,255,0,0), rgba(0,255,0,.5))

transition: background-color .5s

}

.box:hover {

background-color: purple

}

四、借助伪元素和opacity实现渐变过渡

借助伪元素创建变换后的渐变效果,通过改变覆盖的渐变的opacity透明度变化实现渐变过渡效果。

下图为hover之后的效果:

相关代码如下:

.box {

max-width: 400pxheight: 200px

background: linear-gradient(to right, olive, green)

position: relative

z-index: 0

}

.box::before {

content: ''

position: absolute

left: 0top: 0right: 0bottom: 0

background: linear-gradient(to right, green, purple)

opacity: 0

transition: opacity .5s

z-index: -1

}

.box:hover::before {

opacity: 1

}

五、结束语

以上就是我所知道的几个方法,当然,肯定还有其他更好的实现,欢迎补充。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

html 图片的过渡效果

京东年货节特惠来袭!精华礼盒现购超值

京东

广告

《风尚坐火箭学习vue》-- 第十二章:Vue中的动画transition

174阅读·0评论·1点赞

2021年11月26日

image target behaviour 和image target的关系_CSS3中用background-image实现粒子动画效果

26阅读·0评论·0点赞

2020年11月20日

background-image的用法

13.8W阅读·2评论·33点赞

2016年9月9日

background-image 详解

1.0W阅读·1评论·7点赞

2014年11月17日

html文字图片过度效果,如何在图片上应用css3过渡属性?

510阅读·0评论·0点赞

2021年6月11日

HTML CSS 动画 实现图片过渡与变换(图片不超过边框范围局部放大)

1499阅读·1评论·4点赞

2021年11月25日

京东年货节,小年狂欢开启!酵素饮料现购超划算,速戳~

京东

广告

html 图片的过渡效果,3个CSS3图片过渡动画特效

1880阅读·0评论·1点赞

2021年6月11日