I have to move a div when the the user scrolls, but need to use pure JavaScript. position: fixed; will not work with the layout. The div’s original position is relative to something else. Is there a simple implementation using an event like onscroll, to detect how many pixels the page moved up or down, and change the position of
Tag: javascript
Improving regex for parsing YouTube / Vimeo URLs
I’ve made a function (in JavaScript) that takes an URL from either YouTube or Vimeo. It figures out the provider and ID for that particular video (demo: http://jsfiddle.net/csjwf/). It works, however as a regex Novice, I’m looking for ways to improve it. The input I’m dealing with, typically looks like this: 1) Right now I’m doing three separate matches, would
Why does the radix for JavaScript’s parseInt default to 8?
Defaulting the radix to 8 (if the string starts with a 0) in JavaScript’s parseInt function annoys me, only because I continue to forgot to pass the optional second argument as 10. I’m looking for an answer telling me why it makes sense to have it default to 8. Answer It only “defaults” to 8 if the input string starts
javascript parse time (minutes:seconds) from milliseconds
How to parse a given amount of milliseconds (e.g. 125230.41294642858) into a time format like: minutes:seconds? Answer
How to check if a string contains text from an array of substrings in JavaScript?
Pretty straight forward. In javascript, I need to check if a string contains any substrings held in an array. Answer There’s nothing built-in that will do that for you, you’ll have to write a function for it, although it can be just a callback to the some array method. Two approaches for you: Array some method Regular expression Array some
navigator.language list of all languages
Where i can see the list of languages and their codes? I want to compare languages and auto-select required language in template. Are they cross-browser equal? Any other solution? Answer This list of languages is defined by the ISO : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes Example : be for belarus, fr for french. If you are looking for something more specific, those are not
Detect when a user leaves a website
I am trying to create my own website access library (for fun) like Google Analytics where I can detect when a user accesses my website, what pages they view etc. Is there a way to determine when the user leaves a page &/or leaves the website for good? I have successfully coded (in python) the detecting when the user 1st
Convert to uppercase as user types using javascript
I want to convert lowercase chars to uppercase as the user types using javascript. Any suggestions are welcome. I have tried the following: Answer
Can someone explain me how jjencode works and if is good to use it on my code
Can someone explain me how http://utf-8.jp/public/jjencode.html works and if is good to use it on my code? The first time I tried it I thought that I needed to have some kind of algorithm in my code to use it, but it works on every site. What is happening? I already read the source code but I don’t understand it.
JavaScript numbers to Words
I’m trying to convert numbers into english words, for example 1234 would become: “one thousand two hundred thirty four”. My Tactic goes like this: Separate the digits to three and put them on Array (finlOutPut), from right to left. Convert each group (each cell in the finlOutPut array) of three digits to a word (this what the triConvert function does).