I am trying to move a menu div on a iPhone device. When I resize the browser window on my desktop, this works. But viewing it on a actual iPhone this doesn't work. But after rotating it on landscape mode it shows up the menu properly and rotating it back on portrait mode it retains the proper view, but refreshing the page it once more shows the wrong view.
I am using viewport <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> and the script is the following:
<script type="text/javascript">
$(window).resize(function () {
var responsive_viewport = $(window).width();
if (responsive_viewport <= 480) {
$("#menu").after($("#header"));
} else {
$("#header").after($("#menu"));
}
});
</script>
There is a simple sample and the actual page is testpage
Thanks
Sohail
The problem is you are doing all the action in .resize(), and it only fires when the window resizes.
You need to do the same action on document ready, you need to check what is the initial screen size when page loads.
Something like this.
function ChangeDiv(width){
if (width <= 480) {
$("#menu").after($("#header"));
} else {
$("#header").after($("#menu"));
}
}
$(function () {
var onLoadWidth = $(window).width();
ChangeDiv(onLoadWidth);
$(window).resize(function () {
var resizeWidth = $(window).width();
ChangeDiv(resizeWidth);
});
})
Related
I have a slider that fades images.
The transition works, the new image fades it, but the previous image doesn't fade out.
The previous image simply disappears after the next image has fully faded in.
For opaque images this of course is perfectly fine as we don't need to the previous image fade out. It's simply overlaid by the new image.
The problem is that my images have transparent regions, so it would be necessary that the previous image fades out.
How could I achieve this?
My current code is this:
jssor_1_slider_init = function() {
var jssor_1_SlideshowTransitions = [
{$Duration:800,$Opacity:2}
];
var jssor_1_options = {
$AutoPlay: 1,
$LazyLoading: 1,
$SlideshowOptions: {
$Class: $JssorSlideshowRunner$,
$Transitions: jssor_1_SlideshowTransitions
}
};
var jssor_1_slider = new $JssorSlider$("jssor_1", jssor_1_options);
/*#region responsive code begin*/
var MAX_WIDTH = 256;
function ScaleSlider() {
var containerElement = jssor_1_slider.$Elmt.parentNode;
var containerWidth = containerElement.clientWidth;
if (containerWidth) {
var expectedWidth = Math.min(MAX_WIDTH || containerWidth, containerWidth);
jssor_1_slider.$ScaleWidth(expectedWidth);
}
else {
window.setTimeout(ScaleSlider, 30);
}
}
Given image with transparent area, to make jssor slider with slideshow, you can use twins transitions.
Open options window, choose one or more twins slideshow transitions.
Followed by documentation and examples on this page
I think you need this {$Duration:700,$Opacity:2,$Brother:{$Duration:700,$Opacity:2}}
Example : Fade Twins
Is it possible to change the aspect ratio when the game is fullscreen in WebGL? If so, does it pillarbox or stretch to compensate for the difference?
Screen.SetResolution(800, 600, true);
does not work in WebGL.
Its not possible in WebGL, because you export with a body and canvas size, not screen resolution.
You need to set your canvas size in your template css file:
<canvas id="c" width="400" height="300"></canvas>
You can call this function to resize your canvas size when you go to full screen o resize your window:
function resizeCanvas() {
canvas = document.getElementById("c");
gl = canvas.getContext("webgl");
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (canvas.width != width ||canvas.height != height)
{
canvas.width = width;
canvas.height = height;
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
}
}
I use this code to show my popup automatically and I want to know how to close it automatically after 5 seconds.
$(document).ready(function() {
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
Modifying an example from Mozilla's developer page on WindowTimers.setTimeout(), call this function from within your existing document.ready function:
delayedAlertClose();
Add these functions outside your document.ready function:
function delayedAlertClose() {
timeoutID = window.setTimeout(popupClose, 5000);
}
function popupClose() {
$('#mask').hide();
$('.window').hide();
}
So the webview should open when i click the "facebook button" which is a image but acts as a button.
Is there a better way to do this, becasue this is not working.
It seemed easy enough with the code though..
var fbbutton = Ti.UI.createImageView({
image:"fb.png",
top:"55%",
zIndex:"1",
height:"15%",
width:"20%",
left:"2%"
});
fbbutton.addEventListener("click" , function(e){
var webview = Titanium.UI.createWebView({url:'http://www.facebook.com'});
var window = Titanium.UI.createWindow();
window.add(webview);
window.open();
});
Try giving the window an explicit open:
fbbutton.addEventListener("click" , function(e){
var webview = Titanium.UI.createWebView({url:'http://www.facebook.com'});
var window = Titanium.UI.createWindow();
window.add(webview);
window.open({modal:true}); // Make modal
});
I am new to Titanium.
I have taken 3 view and want to hide show that view on button click for iPhone app.
Any idea how to achieve this?
You can hide / show a view very easily, heres a self contained example:
var win = Ti.UI.createWindow();
var view = Ti.UI.createView({
width : 100,
height : 100,
backgroundColor : 'red'
});
var redView = Ti.UI.createView({
title : 'Hide / Show Red View',
bottom : 0,
width : 200,
height : 35
});
var visible = true;
button.addEventListener('click', function(e) {
if(visible) {
redView.hide();
} else {
redView.show();
}
visible = !visible;
});
win.add(redView);
win.add(button);
win.open();
While the other answer is certainly useful, two other (slightly) different methods for doing the same thing, just in case Titanium flips out when you use show() and hide().
//Method 1, using part of Josiah Hester's code snippet
var visible = true;
button.addEventListener('click', function(e) {
if(visible) {
redView.setVisible(false); //This is the exact same thing as hide() method
} else {
redView.setVisible(true); //This is the exact same thing as show() method
}
visible = !visible;
});
You can set opacity to 0 and even if the view's visible property is set to true, it will still be invisible, due to a completely nonexistent level of opacity. This is useful if you want something to be visible, but not clickable (by placing a view behind a view with an opacity of zero.
//Method 2, same code section
var opacity = 0;
button.addEventListener('click', function(e) {
if(opacity) {
redView.setOpacity(0); //This is the NOT the same thing as hide() method
} else {
redView.setOpacity(1); //This is the NOT thesame thing as show() method
}
opacity = Math.abs(opacity - 1);
});