Titanium - Changing orientation between windows - ios

I'm developing an application for ipad and iphone using Titanium. You can navigate between different views. 1st view (the main view where you can go to another views) will be only on portrait mode, the rest of views can be in any orientation.
For this, I use different windows:
var winPortrait = Ti.UI.createWindow({
orientationModes : [Ti.UI.PORTRAIT],
fullscreen : false,
navBarHidden : true,
backgroundColor : "#00669c",
});
var appWindow = Titanium.UI.createWindow({
width : Ti.UI.FILL,
height : Ti.UI.FILL,
fullscreen : false,
navBarHidden : true,
backgroundColor : "#00669c",
backgroundImage : "Default-Portrait.png",
orientationModes : [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
This works ok. When I open each window, orientation changes works ok.
To explain my problem, I'm going to specify the steps I do to reproduce it.
I'm viewing a screen on landscape:
I click to go to main view (portrait only) with device in landscape.
Main view is shown in portrait mode.
I rotate the device to portrait.
I go to the view again with device in portrait:
If I change device orientation, I receive the orientation change event, app detects is landscape mode and draw elements like landscape, but window or view (I don't know) its drawing like portrait, so it doesn't adjust correctly:
This doesn't occur on ios 7, but when I've tried with ios 5.1, it happens (I doesn't have a device with ios 6.x to try it)
Do you know how can I solve it or is a SO problem?
Thank you very much.
UPDATE
This is a simplification of the code I use:
In app.js:
var appWindow = Titanium.UI.createWindow({
width : Ti.UI.FILL,
height : Ti.UI.FILL,
fullscreen : false,
navBarHidden : true,
backgroundColor : "#00669c",
backgroundImage : "Default-Portrait.png",
orientationModes : [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
var winPortrait = Ti.UI.createWindow({
orientationModes : [Ti.UI.PORTRAIT],
fullscreen : false,
navBarHidden : true,
backgroundColor : "#00669c",
});
var openView = function(e) {
currentView = e.win;
if (winPortraitHomeOpened && e.win != 'Home') {
appWindow.backgroundImage = '';
appWindow.addEventListener('open', function() {
//alert("appwindowopen")
if (appWindow != null) {
appWindow.height = Ti.UI.FILL;
appWindow.width = Ti.UI.FILL;
}
});
appWindow.open();
}
// Dependiendo de la vista, abre una ventana u otra
if (e.win == 'Home') {
winPortrait.open();
winPortraitHomeOpened = true;
setTimeout(function() {
var Home = require('/views/Home2');
activeView = Home.Constructor(winPortrait);
addActiveViewCloseWin();
}, 10);
} else if (e.win == 'test') {
var Test = require('/views/test/test');
activeView = Test.Constructor(appWindow, true);
}
if (currentView != 'Home') {
addActiveViewCloseWin();
}
};
var addActiveViewCloseWin = function() {
var anim_invisible = Titanium.UI.createAnimation({
opacity : 0,
duration : 300
});
var anim_visible = Titanium.UI.createAnimation({
opacity : 1,
duration : 300
});
if (winPortraitHomeOpened && currentView == 'Home') {
winPortrait.add(activeView);
} else {
appWindow.add(activeView);
}
if (lastActiveView != null) {
Trace.info("lastActiveView != null");
lastActiveView.animate(anim_invisible);
setTimeout(function() {
activeView.animate(anim_visible);
lastActiveView.close();
lastActiveView = activeView;
}, 300);
} else {
activeView.animate(anim_visible);
lastActiveView = activeView;
}
activeView.updateOrientation();
setTimeout(function() {
if (currentView == 'Home') {
appWindow.close();
} else {
if (winPortraitHomeOpened) {
winPortrait.close();
winPortraitHomeOpened = false;
}
}
}, 500);
};
Ti.Gesture.addEventListener('orientationchange', function(e) {
// Comprobar que ha cambiado de orientación. Se envían varios eventos juntos
var _currentOrientacion = 0;
if (utils.isLandscape())
_currentOrientacion = 1;
if (_currentOrientacion == orientacion) {
return;
}
orientacion = _currentOrientacion;
// Se actualiza las dimensiones y la orientación de los elementos
if (!winPortraitHomeOpened && !winPortraitConfOpened) {
if (appWindow != null) {
appWindow.height = Ti.UI.FILL;
appWindow.width = Ti.UI.FILL;
}
}
if (activeView != null) {
activeView.updateOrientation();
}
});
The code of Test.js:
exports.Constructor = function(parent) {
var view = Ti.UI.createView({
height : utils.getScreenHeight(),
width : utils.getScreenWidth(),
backgroundColor : 'red'
});
var cabeceraView = Cabecera.Constructor(view);
view.add(cabeceraView);
cabeceraView.setTitle('Prueba');
var backButton = Ti.UI.createImageView({
image : utils.imagesFolder() + "common/returnHome.png",
//top : view.height / 4,
left : utils.todp(8),
height : utils.todp(25),
width : utils.todp(65)
});
view.add(backButton);
backButton.addEventListener('click', function() {
openView({
win : 'Home'
});
});
var updateFechaCabecera = function() {
fechaView.setFecha('XXXX-XX-XX');
};
view.updateFechaCabecera = updateFechaCabecera;
var fechaView = Fecha.Constructor(view);
view.add(fechaView);
updateFechaCabecera();
// Vista ocupa todo salvo cabecera y fecha
var mainView = Ti.UI.createView({
height : utils.getScreenHeight() - utils.getCabeceraHeight() - utils.getFechaHeight(),
width : '100%',
top : utils.getCabeceraHeight() + utils.getFechaHeight(),
backgroundColor : "transparent",
});
view.add(mainView);
// Create a Label.
var aLabel = Ti.UI.createLabel({
text : 'aLabel',
color : 'pink',
font : {
fontSize : 40
},
textAlign : 'center'
});
// Add to the parent view.
mainView.add(aLabel);
var updateOrientation = function() {
Trace.info("updateOrientation de interconexines height width " + utils.getScreenHeight() + ' ' + utils.getScreenWidth());
view.height = utils.getScreenHeight();
view.width = utils.getScreenWidth();
if (utils.isPortrait()) {
aLabel.text = "PORTRAIT";
} else {
aLabel.text = "LANDSCAPE";
}
};
view.updateOrientation = updateOrientation;
var cerrar = function() {
Trace.info('cerrar Template');
view.visible = false;
view.hide();
if (cabeceraView != null) {
cabeceraView.close();
view.remove(cabeceraView);
cabeceraView = null;
}
if (fechaView != null) {
fechaView.close();
view.remove(fechaView);
fechaView = null;
}
// Eliminamos los elementos de la vista
if (view != null) {
utils.removeChildrens(view);
parent.remove(view);
};
view = null;
};
view.close = cerrar;
return view;
};

Have you tried to remove orientationModes in var winPortrait?
Your code should look like this:
var winPortrait = Ti.UI.createWindow({
fullscreen : false,
navBarHidden : true,
backgroundColor : "#00669c",
});

Related

How to edit "highcharts-label-icon" in highcharts-gantt

Highchart gantt : https://www.highcharts.com/docs/gantt/getting-started-gantt
I want to change this dropdown btn icon to right of text label.
How to edit it?
Jsfiddle : https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/gantt/demo/project-management
This is not possible from the API but you can achieve that by wrapping the renderLabel function.
(function(H) {
const {
addEvent,
isNumber,
isObject,
pick
} = H,
onTickHoverExit = function(label, options) {
var css = isObject(options.style) ? options.style : {};
label.removeClass('highcharts-treegrid-node-active');
if (!label.renderer.styledMode) {
label.css({
textDecoration: css.textDecoration
});
}
},
onTickHover = function(label) {
label.addClass('highcharts-treegrid-node-active');
if (!label.renderer.styledMode) {
label.css({
textDecoration: 'underline'
});
}
},
renderLabelIcon = function(tick, params) {
var treeGrid = tick.treeGrid,
isNew = !treeGrid.labelIcon,
renderer = params.renderer,
labelBox = params.xy,
options = params.options,
width = options.width || 0,
height = options.height || 0,
iconCenter = {
x: labelBox.x + tick.label.getBBox().width + width,
y: labelBox.y - (height / 2)
},
rotation = params.collapsed ? 90 : 180,
shouldRender = params.show && isNumber(iconCenter.y);
var icon = treeGrid.labelIcon;
if (!icon) {
treeGrid.labelIcon = icon = renderer
.path(renderer.symbols['circle'](options.x || 0, options.y || 0, width, height))
.addClass('highcharts-label-icon')
.add(params.group);
}
// Set the new position, and show or hide
icon[shouldRender ? 'show' : 'hide'](); // #14904, #1338
// Presentational attributes
if (!renderer.styledMode) {
icon
.attr({
cursor: 'pointer',
'fill': pick(params.color, "#666666" /* Palette.neutralColor60 */ ),
'stroke-width': 1,
stroke: options.lineColor,
strokeWidth: options.lineWidth || 0
});
}
// Update the icon positions
icon[isNew ? 'attr' : 'animate']({
translateX: iconCenter.x,
translateY: iconCenter.y,
rotation: rotation
});
};
H.wrap(H.Tick.prototype, 'renderLabel', function(proceed) {
var tick = this,
pos = tick.pos,
axis = tick.axis,
label = tick.label,
mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode,
options = axis.options,
labelOptions = pick(tick.options && tick.options.labels, options && options.labels),
symbolOptions = (labelOptions && isObject(labelOptions.symbol, true) ?
labelOptions.symbol : {}),
node = mapOfPosToGridNode && mapOfPosToGridNode[pos],
level = node && node.depth,
isTreeGrid = options.type === 'treegrid',
shouldRender = axis.tickPositions.indexOf(pos) > -1,
prefixClassName = 'highcharts-treegrid-node-',
styledMode = axis.chart.styledMode;
var collapsed,
addClassName,
removeClassName;
if (isTreeGrid && node) {
// Add class name for hierarchical styling.
if (label &&
label.element) {
label.addClass(prefixClassName + 'level-' + level);
}
}
proceed.apply(tick, Array.prototype.slice.call(arguments, 1));
if (isTreeGrid &&
label &&
label.element &&
node &&
node.descendants &&
node.descendants > 0) {
collapsed = axis.treeGrid.isCollapsed(node);
renderLabelIcon(tick, {
color: (!styledMode &&
label.styles &&
label.styles.color ||
''),
collapsed: collapsed,
group: label.parentGroup,
options: symbolOptions,
renderer: label.renderer,
show: shouldRender,
xy: label.xy
});
// Add class name for the node.
addClassName = prefixClassName +
(collapsed ? 'collapsed' : 'expanded');
removeClassName = prefixClassName +
(collapsed ? 'expanded' : 'collapsed');
label
.addClass(addClassName)
.removeClass(removeClassName);
if (!styledMode) {
label.css({
cursor: 'pointer'
});
}
// Add events to both label text and icon
[label, tick.treeGrid.labelIcon].forEach(function(object) {
if (object && !object.attachedTreeGridEvents) {
// On hover
addEvent(object.element, 'mouseover', function() {
onTickHover(label);
});
// On hover out
addEvent(object.element, 'mouseout', function() {
onTickHoverExit(label, labelOptions);
});
addEvent(object.element, 'click', function() {
tick.treeGrid.toggleCollapse();
});
object.attachedTreeGridEvents = true;
}
});
}
});
}(Highcharts))
Demo:
https://jsfiddle.net/BlackLabel/k2rb6zgy/
Extending Highcharts:
https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

iOS: Animated scroll position jumps on long touch gestures

Based on TweenMax, the ScrollTo Plugin and ScrollMagic (this is probably not where the problem came from):
I wanna have a hero section on top of a page, only tweening downwards if the user is scrolling from the very beginning. Everything works as expected on my laptop (MBP). Following problem: If I use a touch-device (iPhone SE, iOS 12.4.1) and use a short touch gesture, the window is tweening to the destination withouth any issue. But if I keep my finger on the screen, the page starts to flicker and jumps back to the top after the tween finished.
Codepen
Since it's not working with Codepen on my mobile device:
Reduced test
Is there any way to fix this behaviour? Already tried to toggle preventDefault with eventListeners on Callbacks as well as setting the position again onComplete.
var vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
// assume the feature isn't supported
var supportsPassive = false;
// create options object with a getter to see if its passive property is accessed
var opts = Object.defineProperty && Object.defineProperty({}, 'passive', { get: function(){ supportsPassive = true }});
// create a throwaway element & event and (synchronously) test out our options
document.addEventListener('test', function() {}, opts);
// var allowScroll = true;
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault) {
e.preventDefault();
}
// if (e.stopImmediatePropagation) {
// e.stopImmediatePropagation();
// }
if (e.stopPropagation) {
e.stopPropagation();
}
e.returnValue = false;
}
function getBodyScrollTop() {
var el = document.scrollingElement || document.documentElement;
return el.scrollTop;
// return window.pageYOffset
}
function setBodyScrollTop(scrollTop) {
var el = document.scrollingElement || document.documentElement;
el.scrollTop = scrollTop;
// window.pageYOffset = scrollTop;
}
function addMousewheelListener() {
if (e.addEventListener)
{
// IE9, Chrome, Safari, Opera
e.addEventListener("mousewheel", preventScroll, supportsPassive ? { passive: false } : false);
// Firefox
e.addEventListener("DOMMouseScroll", preventScroll, supportsPassive ? { passive: false } : false);
}
// IE 6/7/8
else
{
e.attachEvent("onmousewheel", preventScroll);
}
}
function removeMousewheelListener() {
if (e.removeEventListener)
{
// IE9, Chrome, Safari, Opera
e.removeEventListener("mousewheel", preventScroll, supportsPassive ? { passive: false } : false);
// Firefox
e.removeEventListener("DOMMouseScroll", preventScroll, supportsPassive ? { passive: false } : false);
}
// IE 6/7/8
else
{
e.detachEvent("onmousewheel", preventScroll);
}
}
function removeTouchListeners(e) {
window.removeEventListener("touchmove", preventScroll);
window.removeEventListener("touchstart", removeTouchListeners);
window.removeEventListener("touchend", removeTouchListeners);
}
function preventScroll(e) {
// if(TweenMax.isTweening(window) || !allowScroll) {
// e.preventDefault();
// e.stopImmediatePropagation();
preventDefault(e)
// }
}
function deactivateScroll() {
// allowScroll = false;
console.log('fired 1');
// window.addEventListener("touchstart", preventScroll, { passive: false });
window.addEventListener("touchmove", preventScroll, { passive: false });
addMousewheelListener();
}
function activateScroll() {
// allowScroll = true;
removeMousewheelListener();
// var scrollTop = y;
// var scrollTop = getBodyScrollTop;
// setBodyScrollTop(scrollTop);
window.addEventListener("touchstart", removeTouchListeners, { passive: false });
window.addEventListener("touchend", removeTouchListeners, { passive: false });
// var event1 = new Event('touchstart');
// var event2 = new Event('touchmove');
// var event3 = new Event('touchend');
// window.dispatchEvent(event1);
// window.dispatchEvent(event2);
// window.dispatchEvent(event3);
}
var ctrl = new ScrollMagic.Controller();
var sceneLeave = new ScrollMagic.Scene({
triggerElement: "#content",
triggerHook: "onEnter",
offset: 1
})
.addTo(ctrl)
.on("enter", function(event) {
TweenMax.to(window, 1, {
scrollTo: {
y: "#content",
autoKill: false
},
onStart: deactivateScroll,
onComplete: activateScroll
});
});

iOS - Titanium Appcelerator , Create a video gallery with preview

What I want to do is create a video gallery with n video.
Add n view in a ScrollView, a view for each video, and load into every view a picture from the corresponding video (waiting for the loading of each video). While holding down (TouchStart) on a view will be loaded in the view (preview) other images of the video (so to display the video preview directly in the mini view) until the finger is released (touchEnd).
So far , is ok, my problem is that I want by pressing (CLICK) on the mini-view the video was displayed in full screen!
Here is my code
//****************************************************************************************************************
var arr_vidplayer_VARIE = [];
var arr_vidplayer_VARIE_duration = [];
var arr_vidplayer_VARIE_cont = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var timer_VARIE = null;
var num_video_VARIE = 37;
var arr_view_VARIE = [];
var left_VARIE= -200;
var top_VARIE = -100;
var actual_video_VARIE = 1;
//****************************************************************************************************************
var win = Ti.UI.createWindow({
backgroundColor : 'white',
fullscreen : true
});
var scroll_VARIE = Ti.UI.createScrollView({
width : 1024,
height : 700,
top : 0
});
scroll_VARIE.addEventListener("scroll",function(e){
clearInterval(timer_VARIE);
});
//****************************************************************************************************************
function START_VARIE(){
if(actual_video_VARIE <= num_video_VARIE){
if((actual_video_VARIE-1) %4 == 0){
top_VARIE+=150;
left_VARIE=45;
}else{
left_VARIE+=245;
}
CREATE_VIDEO_VARIE(top_VARIE,left_VARIE,actual_video_VARIE);
}
}
function CREATE_VIDEO_VARIE(top,left,id){
var myurl = "/video/"+id+".mov";
var video = Titanium.Media.createVideoPlayer({
url : myurl,
mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
fullscreen : true,
id : parseInt(id),
autoplay : true,
//zIndex : 9999999999999
//visible : false
});
video.addEventListener("loadstate",function(e){
END_LOAD_VARIE(e.source.id,e.loadState);
});
arr_vidplayer_VARIE.push(video);
var view_video = Ti.UI.createView({
width : 200,
height : 120,
left : left,
top : top,
id : parseInt(id),
borderColor : "black"
});
view_video.addEventListener("touchstart",function(e){
var i = parseInt(e.source.id) - 1;
timer_VARIE = setInterval(function(e){
if(arr_vidplayer_VARIE_cont[i] < arr_vidplayer_VARIE_duration[i]){
arr_vidplayer_VARIE_cont[i]++;
var img = arr_vidplayer_VARIE[i].thumbnailImageAtTime(arr_vidplayer_VARIE_cont[i],Titanium.Media.VIDEO_TIME_OPTION_EXACT);
if(img == "[object TiBlob]"){
try{
arr_view_VARIE[i].children[0].image = arr_vidplayer_VARIE[i].thumbnailImageAtTime(arr_vidplayer_VARIE_cont[i],Titanium.Media.VIDEO_TIME_OPTION_EXACT);
}catch(e){
clearInterval(timer_VARIE);
}
}
}else{
arr_vidplayer_VARIE_cont[i] = 0;
}
},200);
});
view_video.addEventListener("touchend",function(e){
clearInterval(timer_VARIE);
});
view_video.addEventListener("click",function(e){
arr_vidplayer_VARIE[parseInt(e.source.id)-1].play();
Ti.API.info("play "+e.source.id);
});
var image_video = Ti.UI.createImageView({
width : 200,
height : 120,
left : 0,
top : 0,
id : parseInt(id),
});
var activity = Ti.UI.createActivityIndicator({
style : Ti.UI.iPhone.ActivityIndicatorStyle.DARK
});
view_video.add(image_video);
view_video.add(activity);
//win.add(video);
activity.show();
arr_view_VARIE.push(view_video);
scroll_VARIE.add(view_video);
}
function END_LOAD_VARIE(id,state){
if(parseInt(state) == 3){
arr_view_VARIE[id-1].children[1].hide();
arr_view_VARIE[id-1].children[0].image = arr_vidplayer_VARIE[id-1].thumbnailImageAtTime(1,Titanium.Media.VIDEO_TIME_OPTION_EXACT);
arr_vidplayer_VARIE_duration.push(parseInt(arr_vidplayer_VARIE[id-1].getDuration()/1000));
actual_video_VARIE++;
START_VARIE();
}
}
//****************************************************************************************************************
START_VARIE();
win.add(scroll_VARIE);
win.open();
//****************************************************************************************************************
Appcelerator Documentation declare that fullscreen property on iOS, before the movie player's view is visible has no effect. Try:
var video = Titanium.Media.createVideoPlayer({
url : myurl,
mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
fullscreen : false,
id : parseInt(id),
autoplay : true
});
and
view_video.addEventListener("click",function(e){
view_video.setFullscreen(true);
arr_vidplayer_VARIE[parseInt(e.source.id)-1].play();
Ti.API.info("play "+e.source.id);
});

Titanium scrollableView

I developing an application in Titanium. A hava a code with scrollableview.
It is working in Android but doesn't work in IOS, and not show error messages.
The code:
exports.imagescroller = function(images, imgWidth, imgHeight){
var imageCollection = images;
var window = Ti.UI.createWindow({
backgroundColor:'transparent',
});
if(imgWidth == null) {
imgWidth = "100%";
}
if(imgHeight == null) {
imgHeight = "100%";
}
var scrollGallery = Ti.UI.createScrollableView({
layout:'horizontal',
showHorizontalScrollIndicator:true,
showVerticalScrollIndicator:true,
});
var viewCollection = [];
for (var i = 0; i < imageCollection.length; i++) {
var innerView = Ti.UI.createView({
layout:'horizontal',
});
var item = Ti.UI.createImageView({
width : imgWidth,
height: imgHeight,
imageID:i,
defaultImage: imageCollection[0]
});
if (i < 3) {
item.image = imageCollection[i];
}
innerView.add(item);
viewCollection.push(innerView);
}
scrollGallery.addEventListener('scroll', function(e){
if (scrollGallery.currentPage < (imageCollection.length-1)) {
var nxt = scrollGallery.currentPage+1;
scrollGallery.views[nxt].children[0].image = imageCollection[nxt];
}
});
scrollGallery.views = viewCollection;
window.add(scrollGallery);
return window;
};
I use this in the window:
var Scroller = require("imagescroller");
window = Scroller.imagescroller(allData['images']);
Please help me!
Thanks!
Try to use the more cross platform scrollend event:
scrollGallery.addEventListener('scrollend', function(e){
.......
});
Also try giving your ScrollableView an explicit width and height, just to rule that out:
var scrollGallery = Ti.UI.createScrollableView({
layout:'horizontal',
showHorizontalScrollIndicator:true,
showVerticalScrollIndicator:true,
width : "100%"
height : "100%"
});
Try this and its working , before post i tried it.
var win = Ti.UI.createWindow();
var view1 = Ti.UI.createView({
backgroundColor : '#123'
});
var view2 = Ti.UI.createView({
backgroundColor : '#246'
});
var view3 = Ti.UI.createView({
backgroundColor : '#48b'
});
var scrollableView = Ti.UI.createScrollableView({
views : [view1, view2, view3],
showPagingControl : true,
layout : 'horizontal',
showHorizontalScrollIndicator : true,
showVerticalScrollIndicator : true,
});
win.add(scrollableView);
win.open();
its works in android when you set the height of view more then the screen, or set the height of view , Ti.UI.SIZE
it works

How can I manipulate the UI for this jQuery div scroller?

I'm currently using the following code to scroll up/down text... I'd like to make the following modifications to the code, but am struggling on how to achieve it:
Check the location of the text and affect the opacity of the
up/down arrows. When the content of #scroll is at the top, the up (#scroll-up) arrow would be faded back. When the content of #scroll is at the bottom, the down (#scroll-down) arrow be faded back. Every where in between, both button's would be faded in.
Hide the scroll buttons if they are not needed
Here's the current code:
var ele = $('#scroll');
var speed = 25, scroll = 5, scrolling;
$('#scroll-up').mouseenter(function() {
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() - scroll );
}, speed);
});
$('#scroll-down').mouseenter(function() {
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() + scroll );
}, speed);
});
$('#scroll-up, #scroll-down').bind({
click: function(e) {
e.preventDefault();
},
mouseleave: function() {
if (scrolling) {
window.clearInterval(scrolling);
scrolling = false;
}
}
});
Looks like this might do the trick.
$(function() {
var ele = $('#scroll');
var speed = 25, scroll = 5, scrolling;
$("#scroll-up").css('opacity', 0.5);
$('#scroll-up').mouseenter(function() {
// Scroll the element up
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() - scroll );
$("#scroll-up").css("opacity", (ele.scrollTop() == 0) ? 0.5 : 1);
$("#scroll-down").css("opacity", (ele[0].scrollHeight - ele.scrollTop() == ele.outerHeight()) ? 0.5 : 1);
}, speed);
});
$('#scroll-down').mouseenter(function() {
// Scroll the element down
scrolling = window.setInterval(function() {
ele.scrollTop( ele.scrollTop() + scroll );
$("#scroll-up").css("opacity", (ele.scrollTop() == 0) ? 0.5 : 1);
$("#scroll-down").css("opacity", (ele[0].scrollHeight - ele.scrollTop() == ele.outerHeight()) ? 0.5 : 1);
}, speed);
});
$('#scroll-up, #scroll-down').bind({
click: function(e) {
// Prevent the default click action
e.preventDefault();
},
mouseleave: function() {
if (scrolling) {
window.clearInterval(scrolling);
scrolling = false;
}
}
});
var winHeight = $(window).height();
$("#scroll").css("height", winHeight - 220);
if (ele[0].scrollHeight == ele.outerHeight()){
$("#contentscrollnav").hide();
}
});
$(window).resize(function() {
var winHeight = $(window).height();
$("#scroll").css("height", winHeight - 220);
var ele = $('#scroll');
if (ele[0].scrollHeight <= ele.outerHeight()){
$("#contentscrollnav").hide();
} else if (ele[0].scrollHeight > ele.outerHeight()) {
$("#contentscrollnav").show();
}
});
You can see the code in action at:
http://jsfiddle.net/MzDst/11/

Resources