patternjavascriptMinor
YouTube video intro, and autoscroll when video ends
Viewed 0 times
videoyoutubeendsintroandautoscrollwhen
Problem
This code creates an intro video using the Youtube API, screen text written by JavaScript with a typewriter kind of effect. How can I rewrite this as succinct object-oriented code? Also, I'm not sure if the way I've handled the
setInterval and setTimeout functions is optimal. It works but I know it's far from perfect.var showText;
var loopText;
function typeWords(){
var type=document.getElementById('typer');
var pitch=[
'I am a web developer...based in Manhattan, NY',
'my passion is cutting edge web development',
'I approach each project with the goal of crafting something unique',
'my goal? distinguish your brand, complement your buisiness strategy',
'LETS TALK'
];
var text;
var pitchCount=0;
var str='';
function runtext(){
//update where we are in pitch array
console.log(pitchCount);
str=pitch[pitchCount];
console.log(str);
text=str.split("");
count=0;
type.innerHTML+='';
//console.debug(text);
var showText=setInterval( function(){
//console.debug(text);
if (count"+text[count]+"";
}
count++;}, 50);
}//*end runtext()
loopText=setInterval(function(){
if(pitchCount winPos){ moveWin(yValue,winPos) };
}, 10);
}
function onPlayerStateChange(event)
{
if (event.data==YT.PlayerState.ENDED)
{
//when the player stops scroll window so
//top of next div is at the top of the window.
done=true;
moveWin(yVal,winPosition);
};
}Solution
-
First off, style. There are some major style issues with your code that I'd like to address. Naming is less of an issue here, but more of a general issue with the way you've spaced your code and such.
-
Remove commented out lines of code. If you aren't using them, there's no need to have them. They should be removed.
First off, style. There are some major style issues with your code that I'd like to address. Naming is less of an issue here, but more of a general issue with the way you've spaced your code and such.
- First off, you need space between operators. You need to have one space before an operator, and after it. For example, and equals comparison would look like this:
1 == 2, or a variable declaration:var x = 0;
- Secondly, you have a lot of extra, unneeded blank lines. These can be removed, as it makes code look inconsistent, and not so great.
- You're mixing to curly brace styles, choose one, or the other. Don't mix the two styles, as, again, it will look inconsistent.
- Finally, on style, you have a lot of extra spaces. Remove these.
-
Remove commented out lines of code. If you aren't using them, there's no need to have them. They should be removed.
- Finally, add some more comments to this. Specifically for functions, and above hard-to-read blocks of code. Your code will be much easier to read after this.
Context
StackExchange Code Review Q#87605, answer score: 2
Revisions (0)
No revisions yet.