Jquery/Javascript - On scroll down, change height and position of a textarea - javascript

I'm looking for a way to do an effect which is most likely a combination of things, the base of it would be something like this:
http://nikestadiums.com/
As you can see, when you scroll down, a div is actually sliding up. I am not sure there is such a plugin, and if there is, is it possible to resize and maybe re-position elements as you scroll down?
I've seen the post:
How to make div scroll down with a page once it reaches top of page?
and I know of sticky elements http://imakewebthings.github.com/jquery-waypoints/sticky-elements/
Is it even possible to do something like this? If yes, can you give me links/examples please?
And of course I need to make it super super smooth like the Nike one...ha
Here is a jsfiddle, but I can't get it to work right.
http://jsfiddle.net/3U2Gj/65/
Thanks.

I've modified your JSFiddle. I tested it in Chrome, Firefox, and IE7+.
http://jsfiddle.net/t0nyh0/aMXRq/3/
I've cleaned it up a bit and moved all your "states" into classes. On scroll, it simply uses JQuery to add and remove classes based on the scroll position.
Note that there is no animation, if you wish to animate it, you can use class transitions to animate. See more here: http://docs.jquery.com/UI/Effects/ClassTransitions.
In regards to entering full mode on keydown, you can again create an "expand" class and apply it upon keydown. You can then structure your CSS as follows:
.minState3.expand { }
and to show the button again
.minState3.expand button { display:block; }
Doing it this way allows you the flexibility to define how it looks based on the different states.

Related

Show scrollbars on iOS when scrolling via Javascript

I would like the vertical scrollbar to be displayed when I call element.scrollTop = <somePosition>;
Here is an example of what I'm trying to achieve: https://plnkr.co/edit/0ls05cCa3XrvrWPO?open=lib%2Fscript.js&preview
If that example is loaded on iOS, when the left box is scrolled, the right box should sync with it. That works just fine, but I need a way for the scrollbar to also show up.
I think your issue is that division being scrolled via Javascript is not recognized as active, to keep scrollbar visible.
I would suggest to try any custom Scrollbar library, they manage scrollbars with divisions rather than browser's.
Many such would allow you to configure scrollbar to be shown and hidden using Javascript.
It would add additional work for you, but it can be a solution to go with.
Here are few you can try with: https://www.jqueryscript.net/blog/Best-Custom-Scroll-Bar-jQuery-Plugins.html
You could dynamically add a css class to the container when performing scrollTop().
Try a class that implements overflow-y: scroll when applied. That should yield the desired effect.

Left and right navigation in horizontal listview in winjs

How do we implement like Windows store does? Left and right navigational arrows with animations for 'Listview'? I tried, 'Flipview', 'HubControl', and also, when ever I try 'ensureVisible' on 'Listview', there are no animations in 'Listview'. How do I achieve animating content while navigating with left and right arrows?
Sorry, misunderstood your question before. I think you'll have to use a ListView and draw your own buttons on a layer above it.
When you push a button, you can get the current scroll position of the ListView using the scrollPosition property. Get the current width of the ListView and add to or subtract that from the scrollPosition. However, this does not animate the scrolling automatically.
You can also use the ensureVisible() method to scroll to a particular item.
To get the ListView to animate when jumping to a new position, I think you're going to have to use WinJS.UI.executeAnimation to do it.
https://msdn.microsoft.com/en-us/library/windows/apps/hh779762.aspx
I've done it before, but I honestly can't remember exactly how it works. I know you'll have to setup some rules for how the animation behaves in CSS and then run it asynchronously in javascript.
WinJS.UI.Pivot has arrows with ListViews in the playground.
http://winjs.azurewebsites.net/#pivot
So does WinJS.UI.FlipView
http://winjs.azurewebsites.net/#flipview
But maybe you want the WinJS.UI.NavBar
http://winjs.azurewebsites.net/#navbar

How to move left to right a div on scroll?

I would like to animate in js a simple div on scroll as you can find here grooveshark.
As you can see, the animation reacts to scroll up/down and move horizontally.
This is typically what I need. How can I easily determine this feature in js? Thanks
It's called parallax.
You can achieve this yourself using a combination of CSS attribute changes and scroll detection events, or just use a plugin like SkrollR http://prinzhorn.github.io/skrollr/
For this particular example, you can see the inline styles of that div being changed on scroll (in developer tools):
<div class="albums-holder" style="background-position: 1174px 50%;">...
You can do this on the scroll event:
$(window).scroll(function() {
$(".albums-holder").css( "background-position", [VALUE]);
});
Where [VALUE] would be computed by incrementing/decrementing the background-position by a value each time.
EDIT: I failed to mention, my answer is based on the assumption you have jQuery on the page, I would recommend it is for tasks like this anyway.

Detect when multiple elements are at top of browser screen

Here is the setup, I have multiple divs on a page which are full widths and have blocks of color. The number of divs can vary from page to page. Each div with have a class associated to it (light or dark) and I have a logo pinned to the top of the browser window.
What I am trying to accomplish is this. I want to detect when each on of these div (with a common class) reach the top of the browser window. I then want to see if it has a light or dark class (only this div that just reached the top.) and then change the logo on the page depending on that value.
The closest thing I have come across is some onscreen jquery plugins that will add an :onscreen value to the current div that is on the screen. This would be great if I could only add this onscreen attribute when it reaches the top rather than just into view.
Does anyone have any suggestions as to how one might accomplish this?
// jsfiddle example
http://jsfiddle.net/UhrrR/
Funny, I was just looking at a library that does this very thing:
http://imakewebthings.com/jquery-waypoints/
You can add listeners to your elements that will fire off when your element hits the top of the viewport:
$('#myDiv').waypoint(function() {
var color = $(this).css('background-color');
$('img.logo').attr('src', 'logo.png');
});
For an amazing demo of it in use:
http://tympanus.net/codrops/2013/07/16/on-scroll-header-effects/
I completely agree with Chris Hardie that Waypoints is the way to go. I built a simple example based on your description.
https://github.com/imakewebthings/jquery-waypoints
http://codepen.io/cgspicer/pen/FrCgI
Here is the fiddle, I've used my own, because I've started before you posted your fiddle, but the idea is pretty the same.
I have a position of a logo element, and when scroll happens I check whether one of the desired blocks intersects logo block. On success a class from a custom data-trigger-class attribute is assigned to a logo element.

Smooth scroll div horizontally by a pixel amount, no scrollbars

I've got 10 floating DIVs in a container DIV that I want to be able to scroll through using a button.
I'd like to use left/right buttons to make the container DIV scroll 300px horizontally to display the next floating DIV.
I'd like the width of the container to appear as 100% of the window, and I'd also like there to be no horizontal scroll-bar on the bottom. If it could scroll sideways that'd be great but it's not a must have.
Here's what I've got:
http://jsfiddle.net/696je/
I'm just looking for a function and the way to activate the function for left/right buttons.
I've tried Google for hours, I've tried Flesler's ScrollTo but I haven't had any luck, it might be something do to with the way I've got the width set up, anyway, thanks for your help.
It is possible to do with mix of CSS (display:inline-block and white-space:nowrap) and jQuery (scrollLeft)
here is a jsFiddle implementation with minimum possible wrappers.
I was a little confused by your code you posted in the jsFiddle. You said you wanted no horizontal scroll bars, yet your stuff was set up that way. I went with the horizontal scroll bar since that is what you were going with in your code.
I made a working function here jsFiddle. To get it to work in the frame you need to put focus in the "Result" window (just click anywhere), then use your left and right arrows.
I must give the javascript for keypress credit from this post

Categories

Resources