自定义动画菜单CSS / jQuery [英] Custom animation menu CSS/ jQuery
问题描述
我有这个代码片段,想知道是否有任何修改它的可能性,以便获得后悬停翻译,保持到位或移动几个像素到右侧点击事件,直到另一个菜单botton
// mynewmenu implementation $('nav ul li')。mouseover(function(e){/ /设置美学(类似于:hover)$('nav ul li')。removeClass('hovered'); $(this).addClass('hovered');}); var pageSize = 4,$ links = $ (.pagedMenu li),count = $ links.length,numPages = Math.ceil(count / pageSize),curPage = 1; showPage(curPage); function showPage(whichPage){var previousLinks = pageSize,nextLinks =(previousLinks + pageSize); $ links.show(); $ links.slice(0,previousLinks).hide(); $ links.slice(nextLinks).hide(); showPrevNext();} function showPrevNext(){if((numPages> 0)&&(curPage< numPages)){$(#nextPage)。removeClass('hidden'); $(#msg)。text((+ curPage +of+ numPages +)); } else {$(#nextPage)。addClass('hidden'); } if((numPages> 0)&&(curPage> 1)){$(#prevPage)。removeClass('hidden'); $(#msg)。text((+ curPage +of+ numPages +)); } else {$(#prevPage)。addClass('hidden'); (click,function(){showPage(++ curPage);}); $(#prevPage)。 --curPage);});
.hidden {display :none;} body {font:normal 1.0em Arial,sans-serif;} nav.pagedMenu {color:red; font-size:2.0em; line-height:1.0em; width:8em;位置:固定; top:50px;} nav.pagedMenu ul {list-style:none; margin:0; padding:0;} nav.pagedMenu ul li {height:1.0em; padding:0.15em;位置:相对; border-top-right-radius:0em; border-bottom-right-radius:0em; -webkit-transition:-webkit-transform 220ms,background-color 200ms,color 500ms; transition:transform 220ms,background-color 200ms,color 500ms;} nav.pagedMenu ul li.hovered {-webkit-transform:translateX(1.5em); transform:translateX(1.5em);} nav ul li:hover a {transition:color,1200ms; color:red;} nav.pagedMenu ul li span {display:block; font-family:Arial; position:absolute; font-size:1em; line-height:1.25em; height:1.0em; top:0; bottom:0; margin:auto;右:0.01em; color:#F8F6FF;} a {color:gold; transition:color,1200ms; text-decoration:none;}#pagination,#prevPage,#nextPage {font-size:1.0em;颜色:金色; line-height:1.0em; padding-top:250px; padding-left:5px;}
< script src = https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"> ;</script> ;<nav class =pagedMenu> < ul style =font-size:28px;> < li class =style =margin-bottom:5px;>< a href =#>链接1< / a>< / li& < li class =style =margin-bottom:5px;>< a href =#>链接2< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接3< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接4< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接5< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接6< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接7< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接8< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接9< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接10< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接11< / a>< / li> < li class =style =margin-bottom:5px;>< a href =#>链接12< / a>< / li> < / ul>< / nav>< div id =pagination> < a href =#id =prevPageclass =hidden>上一页< / a>& nbsp;& nbsp; < a href =#id =nextPageclass =hidden>下一页< / a> < span id =msg>< / span>< / div>
此处的实例。
b $ b已点击。
添加了 .toggleClass()
, .hasClass()
, .not()
, .siblings()
, .hover()
to jsfiddle https://jsfiddle.net/ kjhtswp9 / 最初由@ CY5创建,维护悬停翻译效果
$(function ).click(function(e){//设置美观(类似于:hover)$('nav ul li').not(。clicked)。removeClass('hovered').filter(this).addClass (点击悬停).siblings()。toggleClass(clicked hovered,false); })。hover(function(){$(this).addClass(hovered)},function(){$(this).not(。clicked)removeClass(hovered)}); var pageSize = 4,$ links = $(。pagedMenu li),count = $ links.length,numPages = Math.ceil(count / pageSize),curPage = 1; showPage(curPage); function showPage(whichPage){var previousLinks =(whichPage - 1)* pageSize,nextLinks =(previousLinks + pageSize); $ links.show(); $ links.slice(0,previousLinks).hide(); $ links.slice(nextLinks).hide(); showPrevNext(); } function showPrevNext(){if((numPages> 0)&&(curPage< numPages)){$(#nextPage)。removeClass('hidden'); $(#msg)。text((+ curPage +of+ numPages +)); } else {$(#nextPage)。addClass('hidden'); } if((numPages> 0)&&(curPage> 1)){$(#prevPage)。removeClass('hidden'); $(#msg)。text((+ curPage +of+ numPages +)); } else {$(#prevPage)。addClass('hidden'); }} $(#nextPage)。on(click,function(){showPage(++ curPage);}); $(#prevPage)。on(click,function(){showPage( - curPage);});});
.hidden {display:none;} body {font:normal 1.0em Arial,sans-serif;} nav.pagedMenu {color:red; font-size:2.0em; line-height:1.0em; width:8em;位置:固定; top:50px;} nav.pagedMenu ul {list-style:none; margin:0; padding:0;} nav.pagedMenu ul li {height:1.0em; padding:0.15em;位置:相对; border-top-right-radius:0em; border-bottom-right-radius:0em; -webkit-transition:-webkit-transform 220ms,background-color 200ms,color 500ms; transition:transform 220ms,background-color 200ms,color 500ms;} nav.pagedMenu ul li.hovered {-webkit-transform:translateX(1.5em); transform:translateX(1.5em);} nav ul li:hover a {transition:color,1200ms; color:red;} nav.pagedMenu ul li span {display:block; font-family:Arial; position:absolute; font-size:1em; line-height:1.25em; height:1.0em; top:0; bottom:0;边距:auto;右:0.01em;颜色:#F8F6FF;} a {color:gold; transition:color,1200ms; text-decoration:none;}#pagination,#prevPage,#nextPage {font-size:1.0em;颜色:金色; line-height:1.0em; padding-top:250px; padding-left:5px;}
< script src = https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"> ;</script> ;<nav class =pagedMenu> < ul style =font-size:28px;> < li class =style =margin-bottom:5px;>< a href =#>链接1< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接2< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接3< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接4< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接5< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接6< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接7< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接8< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接9< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接10< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接11< / a> < / li> < li class =style =margin-bottom:5px;>< a href =#>链接12< / a> < / li> < / ul>< / nav>< div id =pagination> < a href =#id =prevPageclass =hidden>上一页< / a>& nbsp;& nbsp; < a href =#id =nextPageclass =hidden>下一页< / a> < span id =msg>< / span>< / div>
jsfiddle http://jsfiddle.net/kjhtswp9/3
I have this code snippet and wanted to know if there is any possibility to modify it, in order to obtain after hover translation, keeping in place or moving a few more pixels to the right on click event, until another menu botton will be clicked.
// mynewmenu implementation
$('nav ul li').mouseover(function(e){
//Set the aesthetics (similar to :hover)
$('nav ul li').removeClass('hovered');
$(this).addClass('hovered');
});
var pageSize = 4,
$links = $(".pagedMenu li"),
count = $links.length,
numPages = Math.ceil(count / pageSize),
curPage = 1
;
showPage(curPage);
function showPage(whichPage) {
var previousLinks = (whichPage - 1) * pageSize,
nextLinks = (previousLinks + pageSize);
$links.show();
$links.slice(0, previousLinks).hide();
$links.slice(nextLinks).hide();
showPrevNext();
}
function showPrevNext() {
if ((numPages > 0) && (curPage < numPages)) {
$("#nextPage").removeClass('hidden');
$("#msg").text("(" + curPage + " of " + numPages + ")");
} else {
$("#nextPage").addClass('hidden');
}
if ((numPages > 0) && (curPage > 1)) {
$("#prevPage").removeClass('hidden');
$("#msg").text("(" + curPage + " of " + numPages + ")");
} else {
$("#prevPage").addClass('hidden');
}
}
$("#nextPage").on("click", function() {
showPage(++curPage);
});
$("#prevPage").on("click", function() {
showPage(--curPage);
});
.hidden {
display: none;
}
body {
font: normal 1.0em Arial, sans-serif;
}
nav.pagedMenu {
color: red;
font-size: 2.0em;
line-height: 1.0em;
width: 8em;
position: fixed;
top: 50px;
}
nav.pagedMenu ul {
list-style: none;
margin: 0;
padding: 0;
}
nav.pagedMenu ul li {
height: 1.0em;
padding: 0.15em;
position: relative;
border-top-right-radius: 0em;
border-bottom-right-radius: 0em;
-webkit-transition:
-webkit-transform 220ms, background-color 200ms, color 500ms;
transition: transform 220ms, background-color 200ms, color 500ms;
}
nav.pagedMenu ul li.hovered {
-webkit-transform: translateX(1.5em);
transform: translateX(1.5em);
}
nav ul li:hover a {
transition: color, 1200ms;
color: red;
}
nav.pagedMenu ul li span {
display:block;
font-family: Arial;
position: absolute;
font-size:1em;
line-height: 1.25em;
height:1.0em;
top:0; bottom:0;
margin:auto;
right: 0.01em;
color: #F8F6FF;
}
a {
color: gold;
transition: color, 1200ms;
text-decoration: none;
}
#pagination, #prevPage, #nextPage {
font-size: 1.0em;
color: gold;
line-height: 1.0em;
padding-top: 250px;
padding-left: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="pagedMenu">
<ul style="font-size: 28px;">
<li class="" style="margin-bottom: 5px;"><a href="#">Link 1</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 2</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 3</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 4</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 5</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 6</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 7</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 8</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 9</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 10</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 11</a></li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 12</a></li>
</ul>
</nav>
<div id="pagination">
<a href="#" id="prevPage" class="hidden">Previous</a>
<a href="#" id="nextPage" class="hidden">Next</a>
<span id="msg"></span>
</div>
A live example here.
after hover translation, keeping in place or moving a few more pixels to the right on click event, until another menu botton will be clicked.
Added .toggleClass()
, .hasClass()
, .not()
, .siblings()
, .hover()
to jsfiddle https://jsfiddle.net/kjhtswp9/ originally created by @CY5 , maintaining hover translation effect
$(function () {
$('nav ul li').click(function (e) {
//Set the aesthetics (similar to :hover)
$('nav ul li')
.not(".clicked").removeClass('hovered')
.filter(this).addClass("clicked hovered")
.siblings().toggleClass("clicked hovered", false);
}).hover(function () {
$(this).addClass("hovered")
}, function () {
$(this).not(".clicked").removeClass("hovered")
});
var pageSize = 4,
$links = $(".pagedMenu li"),
count = $links.length,
numPages = Math.ceil(count / pageSize),
curPage = 1;
showPage(curPage);
function showPage(whichPage) {
var previousLinks = (whichPage - 1) * pageSize,
nextLinks = (previousLinks + pageSize);
$links.show();
$links.slice(0, previousLinks).hide();
$links.slice(nextLinks).hide();
showPrevNext();
}
function showPrevNext() {
if ((numPages > 0) && (curPage < numPages)) {
$("#nextPage").removeClass('hidden');
$("#msg").text("(" + curPage + " of " + numPages + ")");
} else {
$("#nextPage").addClass('hidden');
}
if ((numPages > 0) && (curPage > 1)) {
$("#prevPage").removeClass('hidden');
$("#msg").text("(" + curPage + " of " + numPages + ")");
} else {
$("#prevPage").addClass('hidden');
}
}
$("#nextPage").on("click", function () {
showPage(++curPage);
});
$("#prevPage").on("click", function () {
showPage(--curPage);
});
});
.hidden {
display: none;
}
body {
font: normal 1.0em Arial, sans-serif;
}
nav.pagedMenu {
color: red;
font-size: 2.0em;
line-height: 1.0em;
width: 8em;
position: fixed;
top: 50px;
}
nav.pagedMenu ul {
list-style: none;
margin: 0;
padding: 0;
}
nav.pagedMenu ul li {
height: 1.0em;
padding: 0.15em;
position: relative;
border-top-right-radius: 0em;
border-bottom-right-radius: 0em;
-webkit-transition: -webkit-transform 220ms, background-color 200ms, color 500ms;
transition: transform 220ms, background-color 200ms, color 500ms;
}
nav.pagedMenu ul li.hovered {
-webkit-transform: translateX(1.5em);
transform: translateX(1.5em);
}
nav ul li:hover a {
transition: color, 1200ms;
color: red;
}
nav.pagedMenu ul li span {
display: block;
font-family: Arial;
position: absolute;
font-size: 1em;
line-height: 1.25em;
height: 1.0em;
top: 0;
bottom: 0;
margin: auto;
right: 0.01em;
color: #F8F6FF;
}
a {
color: gold;
transition: color, 1200ms;
text-decoration: none;
}
#pagination,
#prevPage,
#nextPage {
font-size: 1.0em;
color: gold;
line-height: 1.0em;
padding-top: 250px;
padding-left: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="pagedMenu">
<ul style="font-size: 28px;">
<li class="" style="margin-bottom: 5px;"><a href="#">Link 1</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 2</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 3</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 4</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 5</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 6</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 7</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 8</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 9</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 10</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 11</a>
</li>
<li class="" style="margin-bottom: 5px;"><a href="#">Link 12</a>
</li>
</ul>
</nav>
<div id="pagination">
<a href="#" id="prevPage" class="hidden">Previous</a>
<a href="#" id="nextPage" class="hidden">Next</a>
<span id="msg"></span>
</div>
jsfiddle http://jsfiddle.net/kjhtswp9/3
这篇关于自定义动画菜单CSS / jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!