sHover是一个纯原生JavaScript编写的小组件,不需要引入JQuery或其他插件就可以使用。使用非常简单,引入sHover的js文件之后,只需一行代码,即可让你的图片展示瞬间炫酷起来
有很多不同的效果可以在创建默认的效果之后进行设置,并且设置方法非常简单。可以设置悬浮层在运动时的许多状态。
它的在所有新版本的浏览器上都能完美运行,除此之外,它甚至能在IE5及以前的浏览器上运行,并且效果几乎没有影响(由于这个页面用了大量CSS3的属性,而我实在懒得做更多修改,所以这个页面会在低版本浏览器下变乱,但是JS效果绝对不会出问题!)
<div class="example1"> <span class="intro1"></span> </div> .example1{ width: 300px; height: 300px; background:powderblue; } .intro1{ background:firebrick; }
var example1=new sHover("example1","intro1");
悬浮层滑入滑出的速度,默认值为5,取值范围0-10
example1.set({ speed:7 });
设置悬浮层的最终透明度,默认值为100,取值范围0-100
example1.set({ opacity:80 });
默认值为false,可设为true
example1.set({ opacityChange:true });
example1.set({ speed:7, opacity:80, opacityChange:true });
Flowers are so inconsistent! But I was too young to know how to love her
one loves the sunset, when one is so sad
For she did not want him to see her crying. She was such a proud flower
It is of some use to my volcanoes, and it is of some use to my flower, that I own them. But you are of no
I thought that I was rich, with a flower that was unique in all the world; and all I had was a common
For she did not want him to see her crying. She was such a proud flower
She has only four thorns to defend herself against the world. And I have left on my planet, all alone!
To me, you are still nothing more than a little boy who is just like a hundred thousand other little boys.
And I have no need of you. And you, on your part, have no need of me.
I am nothing more than a fox like a hundred thousand other foxes.
But if you tame me, then we shall need each other.
To me,you will be unique in all the world. To you, I shall be unique in all the world.
为所有元素加上统一的class,以方便统一设置运动效果和样式,可以在主容器和悬浮页内放入任何你需要元素,也可以给他们加上你喜欢的样式。我在主容器里放了一张图片,悬浮窗内放了标题,文章和按钮。
<div id="item1" class="sHoverItem"> <img id="img1" src="images/1.jpg"> <span id="intro1" class="sIntro"> <h2>Flowers</h2> <p> Flowers are so inconsistent! </p> <button>inconsistent</button> </span> </div>
根据你想要达到的效果,灵活的设置动画效果的各种参数吧!右边是我为这个图片展示界面设置的效果。
var a=new sHover("sHoverItem","sIntro"); a.set({ slideSpeed:5, opacityChange:true, opacity:80 });