Доброго времени суток!
Javascript |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| $( document ).ready(function() {
var txtZeroID = "#rec70014772";
var open = false;
var close = true;
var resize = false;
$('[href = "#long"]').addClass('activebtn');
function allUp(){
if (!resize){
$("[href='#stepsleft2']").parent(".tn-elem").animate({ top: '-=80' }, 1000);
$("[href='#stepsleft3']").parent(".tn-elem").animate({ top: '-=160' }, 1000);
$("[href='#stepsleft4']").parent(".tn-elem").animate({ top: '-=240'}, 1000);
$("[href='#stepsright6']").parent(".tn-elem").animate({ top: '-=80' }, 1000);
$("[href='#stepsright7']").parent(".tn-elem").animate({ top: '-=160'}, 1000);
$("[href='#stepsright8']").parent(".tn-elem").animate({ top: '-=240'}, 1000);
$("[href='#myline']").parent(".tn-elem").animate({
height : '-=270', }, 1000, function() { });
} else {resize = false;};
$(""+txtZeroID+" .t396__artboard , "+txtZeroID+" .t396__carrier , "+txtZeroID+" .t396__filter").animate({ height : '-=260px' }, 1000);
$('[href = "#txtleft"]').removeClass("showtxt");
$('[href = "#txtright"]').removeClass("showtxt");
close = true;open = false;
};
function allDown(){
$("[href='#stepsleft2']").parent(".tn-elem").animate({ top: '+=80' }, 1000);
$("[href='#stepsleft3']").parent(".tn-elem").animate({ top: '+=160' }, 1000);
$("[href='#stepsleft4']").parent(".tn-elem").animate({ top: '+=240' }, 1000);
$("[href='#stepsright6']").parent(".tn-elem").animate({ top: '+=80' }, 1000);
$("[href='#stepsright7']").parent(".tn-elem").animate({ top: '+=160' }, 1000);
$("[href='#stepsright8']").parent(".tn-elem").animate({ top: '+=240' }, 1000);
$("[href='#myline']").parent(".tn-elem").animate({ height : '+=270' }, 1000);
$(""+txtZeroID+" .t396__artboard , "+txtZeroID+" .t396__carrier , "+txtZeroID+" .t396__filter").animate({height : '+=260px'}, 1000);
$('[href = "#txtleft"]').addClass("showtxt");
$('[href = "#txtright"]').addClass("showtxt");
open = true;close = false;
};
$('[href = "#long"]').click(function (){
$("[href='#long']").attr('href', '#short')
if (close){ allDown()};
});
$('[href = "#short"]').click(function (){
$("[href='#short']").attr('href', '#long')
if (open){ allUp()};
});
var resizeTimeout;
$(window).resize(function(){
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function(){
if (!close){
resize = true;
setTimeout(function() {
$("[href = '#short']")[0].click();
}, 500); }; }, 500);});
}); |
|
Скрипт просто разворачивает информацию при нажатии на кнопку. Когда было 2 кнопки, скрипт прекрасно работал, решил упростить скрипт, упрознил 1 кнопку и теперь при клике у нее меняется href, однако после смены href скрипт перестает работать и не сворачивает информацию обратно. Подскажите, в чем может быть дело?
Добавлено через 1 час 14 минут
Немного исправил этот кусок
Javascript |
1
2
3
4
5
6
7
8
| $('[href = "#long"]').click(function (){
$("[href='#long']").attr('href', '#short')
if (close){ allDown()};
});
$('[href = "#short"]').click(function (){
$("[href='#short']").attr('href', '#long')
if (open){ allUp()};
}); |
|
Теперь Функция открывает и закрывает, но только один раз.
Javascript |
1
2
3
4
5
6
7
8
9
10
11
| $('[href = "#long"]').click(function (f){
$("[href='#long']").attr('href', '#short');
if (close){ allDown();}
f.stopPropagation();
$('[href = "#short"]').click(function (n){
$("[href='#short']").attr('href', '#long');
if (open){ allUp();}
n.stopPropagation();
});
f.preventDefault(); |
|
К сожалению я совсем не знаком с циклами в jquery, подскажите, как сделать из этого цикл, который будет повторяться бесконечно, или как можно завершить эту функцию, чтобы после выполнения
Javascript |
1
| $('[href = "#short"]').click(function (n){ |
|
функция завершалась и при следующем нажатии использовалась повторно?
Добавлено через 5 часов 54 минуты
Решил проблему добавлением класса и проверкой его наличия.