一個客戶案子剛好需要做一個左側的滑動客服選單,一開始不出現捲軸往下時滑動出現,然後卷軸到底自動消失,捲軸往上又出現,像是這個樣式
然後滑鼠滑到按鈕會滑出說明文字像是這樣
左側滑動客服選單範例網頁
以下為製作方法教學
1、先去jQuery官網下載jQuery檔並於<head></head>之間引入
<script type="text/javascript" src="jquery.js"></script>
2、於html樣版中增加以下的結構內容
<div id="fixmenu">
<ul>
<li>
<div id="skypemenu">
<div id="fmb01">skype線上客服</div>
<a title="skype線上客服" href="/">skype線上客服</a></div>
</li>
<li>
<div id="qqmenu">
<div id="fmb02">QQ線上客服</div>
<a title="QQ線上客服" href="/">QQ線上客服</a></div>
</li>
<li>
<div id="linemenu">
<div id="fmb03">line加我好友</div>
<a title="line加我好友" href="/">line加我好友</a></div>
</li>
<li>
<div id="maulmenu">
<div id="fmb04">聯絡我們</div>
<a title="聯絡我們" href="/">聯絡我們</a></div>
</li>
</ul>
</div>
3、建立一個fixedmenu.css檔,並於<head></head>之間引入
<link rel="stylesheet" href="fixedmenu.css">
4、用筆記本打開ixedmenu.css,貼上以下css語法
ul {
margin: 0;
padding: 0;
list-style: none;
}
li {
margin: 0;
padding: 0;
list-style: none;
}
#fixmenu {
position: fixed;
opacity: 0;
left: 0px;
width: 74px;
height: 400px;
background: url(img/img01.png) repeat-x left bottom;
z-index: 10000;
top: 150px;
animation-duration: 1s;
animation-timing-function: ease-in-out;/* opacity: 0; */
}
@keyframes slidein {
0% {
opacity: 0;
margin-top: 150px;
}
50% {
opacity: 0.5;
margin-top: -100px;
}
100% {
opacity: 1;
margin-top: 0px;
}
}
@keyframes slidein2 {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 0;
}
}
/*======================按鈕=====================*/
#fixmenu ul {
position: relative;
top: 90px;
}
#skypemenu {
z-index: 1000;
position: relative;
left: 2px;
width: 65px;
height: 64px;
}
#skypemenu a {
background: url(img/img02.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 64px;
}
#qqmenu {
z-index: 1000;
position: relative;
top: 5px;
left: 2px;
width: 68px;
height: 77px;
}
#qqmenu a {
background: url(img/img03.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 77px;
}
#linemenu {
z-index: 1000;
position: relative;
top: 15px;
left: 2px;
width: 64px;
height: 63px;
}
#linemenu a {
background: url(img/img04.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 63px;
}
#maulmenu {
z-index: 1000;
position: relative;
top: 28px;
left: 4px;
width: 63px;
height: 64px;
}
#maulmenu a {
background: url(img/img05.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 64px;
}
#fmb01 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 10px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb02 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 20px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb03 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 13px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb04 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 13px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb04:after, #fmb03:after, #fmb02:after, #fmb01:after {
content: '';
position: absolute;
top: 30%;
left: 0%;
margin-left: -8px;
width: 0;
height: 0;
border-right: 8px solid #9B4F1D;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
z-index: 100000;
}
@keyframes slidein3 {
0% {
margin-left: 100px;
opacity: 0;
}
70% {
margin-left: -10px;
opacity: 0.5;
}
100% {
margin-left: 0px;
opacity: 0.9;
}
}
@keyframes slidein4 {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 0;
}
} 5、於</body>標籤之後貼上以下的js語法
<script language="javascript">
$(window).scroll(function() {
//取的頂端位置
var $scrollTopa = $(this).scrollTop();
//取的底端位置
var $scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
if(($scrollTopa)>'150'){
$("#fixmenu").css({"animation-name":"slidein","opacity":"1"});
}
if(($scrollBottom)<'100'){
$("#fixmenu").css({"animation-name":"slidein2","opacity":"0"});
}
});
$(document).ready(function(){
$("#skypemenu").mouseover(function(){
$("#fmb01").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#skypemenu").mouseout(function(){
$("#fmb01").css({"animation-name":"slidein4","opacity":"0"});
});
$("#qqmenu").mouseover(function(){
$("#fmb02").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#qqmenu").mouseout(function(){
$("#fmb02").css({"animation-name":"slidein4","opacity":"0"});
});
$("#linemenu").mouseover(function(){
$("#fmb03").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#linemenu").mouseout(function(){
$("#fmb03").css({"animation-name":"slidein4","opacity":"0"});
});
$("#maulmenu").mouseover(function(){
$("#fmb04").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#maulmenu").mouseout(function(){
$("#fmb04").css({"animation-name":"slidein4","opacity":"0"});
});
});
</script>
left: 0px;
width: 74px;
height: 400px;
background: url(img/img01.png) repeat-x left bottom;
z-index: 10000;
top: 150px;
animation-duration: 1s;
animation-timing-function: ease-in-out;/* opacity: 0; */
}
@keyframes slidein {
0% {
opacity: 0;
margin-top: 150px;
}
50% {
opacity: 0.5;
margin-top: -100px;
}
100% {
opacity: 1;
margin-top: 0px;
}
}
@keyframes slidein2 {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 0;
}
}
/*======================按鈕=====================*/
#fixmenu ul {
position: relative;
top: 90px;
}
#skypemenu {
z-index: 1000;
position: relative;
left: 2px;
width: 65px;
height: 64px;
}
#skypemenu a {
background: url(img/img02.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 64px;
}
#qqmenu {
z-index: 1000;
position: relative;
top: 5px;
left: 2px;
width: 68px;
height: 77px;
}
#qqmenu a {
background: url(img/img03.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 77px;
}
#linemenu {
z-index: 1000;
position: relative;
top: 15px;
left: 2px;
width: 64px;
height: 63px;
}
#linemenu a {
background: url(img/img04.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 63px;
}
#maulmenu {
z-index: 1000;
position: relative;
top: 28px;
left: 4px;
width: 63px;
height: 64px;
}
#maulmenu a {
background: url(img/img05.png) no-repeat left top;
display: block;
overflow: hidden;
height: 0px;
padding-top: 64px;
}
#fmb01 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 10px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb02 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 20px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb03 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 13px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb04 {
position: absolute;
width: auto;
white-space: nowrap;
background: #9B4F1D url(../img/menu/fixmenu/) no-repeat left top;
opacity: 0;
top: 13px;
font-size: 130%;
padding: 5px 10px;
color: #FFFFFF;
left: 70px;
animation-duration: 0.5s;
animation-timing-function: ease-in-out;
}
#fmb04:after, #fmb03:after, #fmb02:after, #fmb01:after {
content: '';
position: absolute;
top: 30%;
left: 0%;
margin-left: -8px;
width: 0;
height: 0;
border-right: 8px solid #9B4F1D;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
z-index: 100000;
}
@keyframes slidein3 {
0% {
margin-left: 100px;
opacity: 0;
}
70% {
margin-left: -10px;
opacity: 0.5;
}
100% {
margin-left: 0px;
opacity: 0.9;
}
}
@keyframes slidein4 {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 0;
}
} 5、於</body>標籤之後貼上以下的js語法
<script language="javascript">
$(window).scroll(function() {
//取的頂端位置
var $scrollTopa = $(this).scrollTop();
//取的底端位置
var $scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
if(($scrollTopa)>'150'){
$("#fixmenu").css({"animation-name":"slidein","opacity":"1"});
}
if(($scrollBottom)<'100'){
$("#fixmenu").css({"animation-name":"slidein2","opacity":"0"});
}
});
$(document).ready(function(){
$("#skypemenu").mouseover(function(){
$("#fmb01").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#skypemenu").mouseout(function(){
$("#fmb01").css({"animation-name":"slidein4","opacity":"0"});
});
$("#qqmenu").mouseover(function(){
$("#fmb02").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#qqmenu").mouseout(function(){
$("#fmb02").css({"animation-name":"slidein4","opacity":"0"});
});
$("#linemenu").mouseover(function(){
$("#fmb03").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#linemenu").mouseout(function(){
$("#fmb03").css({"animation-name":"slidein4","opacity":"0"});
});
$("#maulmenu").mouseover(function(){
$("#fmb04").css({"animation-name":"slidein3","opacity":"0.9"});
});
$("#maulmenu").mouseout(function(){
$("#fmb04").css({"animation-name":"slidein4","opacity":"0"});
});
});
</script>
留言
張貼留言