Javascript 如何在jquery中设置反向?
下面的代码是一个jquery脚本,它在单击时使内容翻转,这段代码中的所有内容都可以正常工作,但是翻转方向交替地从右向左然后从左向右翻转,我如何设置方向使其从右向左翻转一个方向Javascript 如何在jquery中设置反向?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,下面的代码是一个jquery脚本,它在单击时使内容翻转,这段代码中的所有内容都可以正常工作,但是翻转方向交替地从右向左然后从左向右翻转,我如何设置方向使其从右向左翻转一个方向 var topCard = 1; var facingUp = true; var totalFaces = $('#flip-content .contents').length; function flipCard(n) { // Replace the contents of the current back-f
var topCard = 1;
var facingUp = true;
var totalFaces = $('#flip-content .contents').length;
function flipCard(n) {
// Replace the contents of the current back-face with the contents
// of the element that should rotate into view.
var curBackFace = $('.' + (facingUp ? 'face2' : 'face1'));
var nextContent = $('#flip-content' + n).html();
var nextContent = $('#flip-content .contents:nth-child(' + n + ')').html();
curBackFace.html(nextContent);
// Rotate the content
$('.card').toggleClass('flipped');
facingUp = !facingUp;
if (topCard === totalFaces) {
topCard = 0;
}
}
$('#flip-content').on('click', function () {
topCard++;
flipCard(topCard);
});
$(document).ready(function () {
// Add the appropriate content to the initial "front side"
var frontFace = $('.face1');
var frontContent = $('#flip-content .contents:first-child').html();
frontFace.html(frontContent);
});
我看不到你的CSS,因为在我发表评论时它还没有发布,但我相信你有一些东西是反向的。你告诉它朝那个方向转,所以无论你在哪里使用这个属性,都要切换它
.card {
rotateY(-180deg);
}
到
而不是使用:
$('.card').toggleClass('flipped');
这将前后翻转您的div
,您需要在每个翻转上添加180度。比如:
var deg=0;
...
deg += 180;
$('.card').css('transform','rotateY('+deg+'deg)');
是我忽略了它,还是在代码片段中没有定义翻转动画?:)所有输入的代码似乎都是有效的,但从我的理解来看,卡片并没有被直观地翻转。但是有一件事,您使用了
var nextContent
两次。问题中有错误,或者代码中有错误?:)我猜您正在使用css3
?
var deg=0;
...
deg += 180;
$('.card').css('transform','rotateY('+deg+'deg)');