/    Sign up×
Community /Pin to ProfileBookmark

Need help modifying a Jquery script

Using PHP im building a bunch of elements from directory structures.

HTML

[code=html]
<div class=”gal”>
<div class=”counter”></div>
<div class=”left_arrow”></div><div class=”right_arrow”></div>
<div class=”slider”>
<div class=”pdf”>1</div>
<div class=”pdf”>2</div>
<div class=”pdf”>3</div>
<div class=”pdf”>4</div>
<div class=”pdf”>5</div>
<div class=”pdf”>6</div>
<div class=”pdf”>7</div>
<div class=”pdf”>8</div>
</div>
</div>
[/code]

Jquery

[CODE]

$(function() {
var c = 1,
boxw = $(‘.pdf’).outerWidth(true),
boxn = $(‘.pdf’).length;

$(‘.slider’).width(boxw*boxn);

//////////////////////////////////
function b(){
cc = (c === 1) ? $(‘.left_arrow’).hide() : $(‘.left_arrow’).show();
ccc =(c >= boxn) ? $(‘.right_arrow’).hide() : $(‘.right_arrow’).show();
}
b();
/////////////////////////////////

function a(cb){
$(‘.slider’).animate({left: ‘-‘+ (boxw)*(c-1) },800, cb);

}
/////////////////////////////////////////////////////////////////
function counter(){
$(‘.counter’).html(c+’/’+boxn);
}
counter();
/////////////////////////////////////////////////////////////////
$(‘.right_arrow’).click(function() {
c++;
b();
a();
counter();
});
$(‘.left_arrow’).click(function() {
c–;
b();
a();
counter();
});

});

[/CODE]

The code works as needed for one directory, the issue is that I need to modify the code to allow for multiple of the HTML .gal elements to be added.
At the moment of course clicking one right arrow moves all the sliders and the counters displays the total number of .pdf elements.

Can anyone please help?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Belrick spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...