Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to make a JavaScript function that will scroll to the next article whenever the down arrow key is pressed. All my HTML elements are dynamic, and are all just article tags with no ID. The script I have so far can recognize the down key being pressed, but from this point, I have no idea how to make a function that will scroll down to the next article tag without naming the articles or something like that.
document.addEventListener('keydown', function(e){
if(e.keyCode === 40) {
// function to scroll down
}});
I think I will need to create a variable that is just any article element within my HTML page. Is that even possible? If so, how would I do that, and make the function scroll down to the next article? Thanks in advance!
You are looking for window.scrollTo function. All you need is to identify Y offset of next article. You can do it by calculating offsetTop of that node (plus all its offsetParent nodes).
Another solution: use element.scrollIntoView() or element.scorllIntoViewIfNeeded(). It's cross-browser too, but I would prefer first solution because it allows you to you can control animation and it will work even in oldest browsers.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So from my understanding of event listeners is that the action only applies to the element that you used the event listener on.
But say that I wanted to listen for a click on one element that is in a separate div, but the element I want to apply certain actions on is in a separate div. What would be the best way if possible in doing so?
To help visualize, im looking at this users example.
https://ryannathanwilson.github.io/Rock_Paper_Scissors/
And so from what it looks like it listens for a click on any of the buttons, and then the clicked button shows up in another area and then performs a specific action. Is this possible? Or am I understanding his code incorrectly and the elements that appear at the bottom when clicked is the original element?
You can write a function like this:
function myfunc(){
document.getElementById("abcd").value = "Lorem Ipsum";
}
And call this function on the element you want to listen on:
<button onclick=myfunc()>Click me! </button>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So I've seen a mouse-hover effect on 2 websites so far and I really like it.
This is the effect I'm talking about.
I'd be grateful if somebody can tell me how to get that effect on my webpage.
It only appears under your cursor when you hover over the page.
The site you have linked in the comments uses the HTML canvas element. But You can simply use already existing libraries for that effect.
Examples mentioned in the comments:
http://jnicol.github.io/particleground/
http://github.com/VincentGarreau/particles.js
Simply, Go to the webpage you wanted to Copy it's effects or anything from it
Right click, View page source
If the effect is made by Css, you will find it in stylesheets tab
If it's using jQuery/Js, Search the head for <script> , Read them and copy the effect (assuming that you understand js/jquery
For more simplicity, use Firebug, open it and just point the cursor at the item you want to see it's source.
But, actually
You can find it at github Here
Change what you want.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a website with a grid of elements that scrolls down. Something very similar than this example:
I would like that, when you click on an element, it zooms in on this element, the other elements disappear, and next to the chosen element's image, some text is displayed. And when you exit this view, the text disappears, and unzoom to the initial view with the grid of all elements.
I don't know how this effect is called - if it ever has a name - and I am having a hard time figuring out how it could be done.. jQuery ? CSS animation ?
I am open to any leads ! Thanks for your help,
I've made a piece of code with jQuery. You can achieve your goal with many ways but here is one.
You can use scale() CSS3 properties to make the zoom on the image and hide() with jQuery to hide the other ones while you click() on one.
If you can't find a solution with these hints, I've made an example of what you wants right here
You can create new div on click with absolute position and display it on front of other elements(bigger z-index)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In the case where Javascript knows which elements are clickable, should Javascript be used to change the mouse cursor (by changing the css) as practically speaking the mouse cursor isn't a style property of the element in question? I am aware this is a question asking to some extend for opinions, so I am looking for an answer which covers both sides of the argument - refers to relevant expertise - and hopefully reaches a conclusion.
Just to be clear, if one would have a clickable list item for example normally one would add in Javascript
someLib.listen("#id li",func);
and in css
#id li{
cursor:pointer;
}
rather than the someLib.listen handling this. For example in my case I was changing the listener from a child element to the parent element and it just seemed to me that it does not follow the rules of separation of logic and presentation that I had to change things in two places.
I tend to use this all the time for 'javascript' created links on non anchor elements ( divs, spans et all )
.jsclick { cursor:pointer }
Then whenever we create an event handler in js we attach this class to it ( as part of the course )
_elementwithhandler.className += ' jsclick';
Not really anything else we can do on non anchor elements. Whether to set it inline or use a class , minor point ..
I'd say use a class - easier ( for others ) to tell in future by the inspect tools which elements have been modified by js
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a huge single page website and would like to show an scroll down hint (icon or something like that) at the bottom of the window when the user visits the website.
The hint should vanish when the visitor either scrolls down or clicks on the icon. I've seen this on several websites which I can't remember now unfortunately. Already been searching on but with no results as I'm probably searching with the wrong keywords...
Anyone has any directions on where to start to achieve this?
Here is a start to get the scroll hint working. Now on styling, that's up to you but I would personally do something like position: absolute and then work from there and give it a zIndex about everything on the page.
$(window).scroll( function() {
if($(document).scrollTop() == 0 ) {
// SHOW scroll hint
} else {
// HIDE scroll hint
}
});
I did this on one of my own web pages.
http://codepen.io/pattmorter/pen/mFDLs
Just check out the javascript and the css.
I think you would need an ID on your icon/link and then have two event listeners. One for clicking on the ID itself and the other onscroll. Once either of those events are fired you can call .remove()
If you don't know where to start, try to read reference of window object. For visibility change you can use opacity, and position attribute to make it fixed at bottom of screen.