图片轮转切换效果

图片轮转切换效果

简介:

  CSS3动画相关的几个属性有:transition, transform animation分别理解为过渡,变换和动画。

  transition指过渡,就是从a点都b点,是有时间的,是连续的,一般针对常规CSS属性;

  transform指变换,如:旋转、缩放,偏移,与transition使用,但是,效果是机械的旋转移动,如果配合transition属性,就会很平滑。

  animation指动画,详见:http://www.cnblogs.com/Michelle20180227/p/8680991.html

案例一:

CSS代码:
.trans_box{
    width: 400px;
    margin: 20px;
    overflow: hidden;
}
.trans_image_box {
    width: 2000px;
    height: 300px;
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
}
.trans_image {
    width: 400px;
    float: left;
}
.trans_image_trigger {
    padding-top: 10px;
    text-align: center;
}
HTML代码:
<div class="trans_box">
    <div id="transImageBox" class="trans_image_box">
        <img class="trans_image" src="http://image.zhangxinxu.com/image/study/p/s500/ps1.jpg" />
        <img class="trans_image" src="http://image.zhangxinxu.com/image/study/p/s500/ps2.jpg" />
        <img class="trans_image" src="http://image.zhangxinxu.com/image/study/p/s500/ps3.jpg" />
        <img class="trans_image" src="http://image.zhangxinxu.com/image/study/p/s500/ps4.jpg" />
    </div>
    <div id="transImageTrigger" class="trans_image_trigger">
        <a href="#1">图片1</a> <a href="#2">图片2</a> <a href="#3">图片3</a> <a href="#4">图片4</a>
    </div>
</div>
JS代码:
(function() {
    var $ = function(id) {
        return document.getElementById(id);
    };
    var oBox = $("transImageBox"),
        oTrigger = $("transImageTrigger").getElementsByTagName("a"),
        lTrigger = oTrigger.length;

    if (oBox && lTrigger) {
        for (var i = 0; i<lTrigger; i+=1) {
            oTrigger[i].onclick = function() {
                var index = Number(this.href.replace(/.*#/g, "")) || 1;
                oBox.style.marginLeft = (1 - index) * 400 + "px";
                return false;
            };
        }
    }
})();

效果:

案例二:

CSS代码:
.anim_image {
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
}
.anim_image_top {
    position: absolute;
    -webkit-transform:scale(1,0);
    opacity: 0;
    filter: Alpha(opacity=0);
}
.anim_box:hover .anim_image_top, .anim_box_hover .anim_image_top {
    opacity: 1;
    filter: Alpha(opacity=100);
    -webkit-transform: scale(1, 1);
}
.anim_box:hover .anim_image_bottom, .anim_box_hover .anim_image_bottom {
    -webkit-transform:rotate(360deg) scale(0,0);
}
HTML代码:
<div id="testBox" class="demo anim_box">
    <img class="anim_image anim_image_top" src="http://image.zhangxinxu.com/image/study/p/s200/ps6.jpg" />
    <img class="anim_image anim_image_bottom" src="http://image.zhangxinxu.com/image/study/p/s200/ps4.jpg" />
</div>

效果图:

案例三:

CSS代码:
@-webkit-keyframes fadeInOut {
    0% {
        opacity:1;
     }
    25% {
        opacity:0;
    }
    50% {
        opacity: 0;
    }
    75% {
        opacity:1;
    }
}
.anim_fade_image {
    position:absolute;
    -webkit-animation-name: fadeInOut;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-duration: 12s;
    -webkit-animation-direction: alternate;
}
HTML代码:
<img class="trans_fade_image" src="http://image.zhangxinxu.com/image/study/p/s200/ps6.jpg" />
<img src="http://image.zhangxinxu.com/image/study/p/s200/ps4.jpg" />

效果图:

案例四:

CSS代码:
.anim_image {
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
    cursor:pointer;
}
.anim_image_top {
    position: absolute;
    -webkit-transform: scale(0, 0);
    opacity: 0;
    filter: Alpha(opacity=0);
}
.anim_box:hover .anim_image_top , .anim_box_hover .anim_image_top {
    opacity: 1;
    filter: Alpha(opacity=100);
    -webkit-transform: scale(1, 1);
    -webkit-transform-origin: top right;
}
.anim_box:hover .anim_image_bottom, .anim_box_hover .anim_image_bottom {
    -webkit-transform: scale(0, 0);
    -webkit-transform-origin: bottom left;
}
HTML代码:
<div id="testBox" class="demo anim_box">
    <img class="anim_image anim_image_top" src="http://image.zhangxinxu.com/image/study/p/s200/ps6.jpg" />
    <img class="anim_image anim_image_bottom" src="http://image.zhangxinxu.com/image/study/p/s200/ps4.jpg" />
</div>

效果图:

案例五:

JS代码:
(function() {
    var oImage = document.getElementById("testBox").getElementsByTagName("img");
    oImage[0].onclick = function() {
        var cl = this.className;
        if (/click/.test(cl)) {
            this.className = "trans_fade_image";
        } else {
            this.className = "trans_fade_image trans_fade_image_click";
        }
    };
})();
CSS代码:
.trans_fade_image {
    position:absolute;
    -webkit-transition: opacity 1s ease-in-out;
    -moz-transition: opacity 1s ease-in-out;
    -o-transition: opacity 1s ease-in-out;
    transition: opacity 1s ease-in-out;
}
.trans_fade_image_click {
    opacity:0;
    filter: alpha(opacity=0);
}
HTML代码:
<div id="testBox" class="demo">
    <img class="trans_fade_image" src="http://image.zhangxinxu.com/image/study/p/s200/ps6.jpg" />
    <img src="http://image.zhangxinxu.com/image/study/p/s200/ps4.jpg" />
</div>

效果图:

原文地址:https://www.cnblogs.com/Michelle20180227/p/8776375.html

时间: 2024-10-29 00:31:43

图片轮转切换效果的相关文章

[JS]图片自动切换效果(学习笔记)

上次在下载的网页中看到 javascript实现图片自动切换效果: <style text="text/css"> /*图片滚动栏*/.container, .container * {    margin: 0;    padding: 0;}.container {    width: 1005px;    height: 395px;    float: right;    overflow: hidden;    position: relative;    rig

手机端图片滑动切换效果

最近公司要求开发wap版本页面,碰到了个图片滑动切换效果,折腾了半天,自己封装了一个比较通用的小控件,在此分享一下. 大概功能:可以自定义是否自动切换,支持单手滑动图片进行切换,支持左右滑动切换.循环切换等等,具体可以拿demo代码自己本地试试,注意只支持手机端哦 大概思路:通过touchstart.touchmove.touchend 三个事件加上css3的3d变化效果配合,实现滑动切换图片, 开发是基于Zepto框架,当然也支持其他任何一款手机端框架,只需将代码中的美元符号$换为指定框架操作

js实现图片自动切换效果。

js实现图片自动切换效果,简单实用,原谅我只是一只小菜鸟还在学大神天天写博文装逼. <script language="javascript"> setInterval(test, 2000); var array = new Array(); var index = 0; var array = new Array("../../Content/images/3s1hj_kqzew4k2ozbhs2dwgfjeg5sckzsew_780x520.jpg"

基于jquery鼠标点击图片翻开切换效果

基于jquery鼠标点击图片翻开切换效果是一款基于jQuery+CSS3实现的点击图片切换特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="container"> <img src="images/1.jpeg" alt="1" /> <img src="images/2.jpeg" alt="2" /> <img s

图片旋转切换效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

一款常用的漂亮的JS图片滑动切换效果

<HTML> <HEAD> <TITLE>一款常用的漂亮的JS图片滑动切换效果丨石家庄展柜制作|</TITLE> <style> BODY { PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px } UL { PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PAD

个人学习JQ插件编写成果:little酷炫的图片滑动切换效果

工作一个多月了,好久没来冒冒泡了,看了@wayong的JQ插件教程,自己编写了一个模仿拉勾网首页广告栏滑动特效的JQ插件,现在跟朋友们分享分享! 先上demo链接:http://runjs.cn/detail/gpowdhhk 快要下班了~先把代码放出来~~回家再编辑~ 这里是HTML代码: 1 <!--js酷炫图片滑动hover效果,类似拉勾网--> 2 <div class="beauty-go-outer" id="my-div"> 3

使用javascript实现图片上下切换效果并且实现顺序循环播放

<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"&g

淘宝首页 图片滑动切换效果 基于CSS3的transition方法实现

与上一文章对比着看效果更佳 <!doctype html> <html> <head> <meta charset="utf-8"> <style> img { height:400px; width:1250px; /*使用relative,才能使用left.top性质*/ position:relative; top:0px; left:0px; transition:left 0.5s; } </style>