Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 10-18-2011, 06:44 AM floating sidebar
flexdesigns's Avatar
Extreme Talker

Posts: 187
Name: Nathaniel
Location: United Kingdom
Trades: 0
ok im a jQuery noob and have just implemented some code into a site im building to allow for a sidebar on a majority of pages to float with the page when scrolling but when the sidebar reaches the footer it keeps pushing it further down the page instead of stopping at that point. also on coming back up the sidebar goes a little too far up instead of stopping in its original position

help with this would be much appreciated

you can see it in action at http://flexdesigns.co.uk/box/dev/dev...nal-injury.php

Code:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>
    <script type="text/javascript">
        $(function() {
            var offset = $(".right").offset();
            var topPadding = 25;
            $(window).scroll(function() {
                if ($(window).scrollTop() > offset.top) {
                    $(".right").stop().animate({
                        marginTop: $(window).scrollTop() - offset.top + topPadding
                    });
                } else {
                    $(".right").stop().animate({
                        marginTop: 10
                    });
                };
            });
        });
    </script>

thanks
__________________
Here to inspire you
Please login or register to view this content. Registration is FREE
flexdesigns is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-18-2011, 08:30 AM Re: floating sidebar
flexdesigns's Avatar
Extreme Talker

Posts: 187
Name: Nathaniel
Location: United Kingdom
Trades: 0
ok the ive solved the part that was causing it to move too far to the top of the page but now need to stop it when it gets to the end of the content area instead of continuing to push down the footer
__________________
Here to inspire you
Please login or register to view this content. Registration is FREE
flexdesigns is offline
Reply With Quote
View Public Profile
 
Old 10-18-2011, 09:04 AM Re: floating sidebar
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
What has jquery got to do with this??

Just use position: fixed and set the parameters to position it where you want it to be
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-18-2011, 09:27 AM Re: floating sidebar
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Example:

http://www.modtalk.co.uk/_site/code/...g/fixed/right/

http://www.modtalk.co.uk/_site/code/...ight/style.css
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-18-2011, 10:41 AM Re: floating sidebar
flexdesigns's Avatar
Extreme Talker

Posts: 187
Name: Nathaniel
Location: United Kingdom
Trades: 0
its got a little animated effect on the sidebar when you scroll thats why im using jquery, i feel it just looks better
__________________
Here to inspire you
Please login or register to view this content. Registration is FREE
flexdesigns is offline
Reply With Quote
View Public Profile
 
Old 10-18-2011, 10:48 AM Re: floating sidebar
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Unless you take the element out of the document flow that is what will happen.



By the way, I think that falls into the "animation because I can" category.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-18-2011, 02:29 PM Re: floating sidebar
flexdesigns's Avatar
Extreme Talker

Posts: 187
Name: Nathaniel
Location: United Kingdom
Trades: 0
its not that bad is it
__________________
Here to inspire you
Please login or register to view this content. Registration is FREE
flexdesigns is offline
Reply With Quote
View Public Profile
 
Old 10-18-2011, 04:18 PM Re: floating sidebar
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's one of those thing that is amusing or entertaining for about thirty five seconds, and to be honest If I came across page that while looking for legal advice, it would be the last place I'd choose.

It's one of those things that just makes you think yeah, right, Ok, bye!

It's a bit like walking into a solicitor's or accountant's office and finding one of those dangling things on elastic that goes BOING!!!! when you pull and release it, hanging above the desk.

It just doesn't convey the right impression for a solicitors website.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-18-2011, 04:20 PM Re: floating sidebar
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Oh, and, there should be a 'u' in "Enquiry"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-18-2011, 04:28 PM Re: floating sidebar
flexdesigns's Avatar
Extreme Talker

Posts: 187
Name: Nathaniel
Location: United Kingdom
Trades: 0
haha ok fixed position it is then. and ill be checking spelling once the design complete i never pay much attention to it whilst its in development as all the words start to look foreign when i see them a million times within a day anyway .

thanks
__________________
Here to inspire you
Please login or register to view this content. Registration is FREE
flexdesigns is offline
Reply With Quote
View Public Profile
 
Old 10-20-2011, 04:04 AM Re: floating sidebar
Novice Talker

Posts: 10
Name: Umar Bukhari
Location: Pakistan
Trades: 0
First of all get the height of the page on load event and save this height in some variable and then add the limit by conditional tag like "if"

For example
Code:
if (page.height == element.top position+element.height) { stop scroll } else { do scroll}

if (element.top position == put some fixed position) { stop scroll } else { do scroll}
angelsdev is offline
Reply With Quote
View Public Profile Visit angelsdev's homepage!
 
Reply     « Reply to floating sidebar
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31699 seconds with 12 queries