Switching background image smoothly - Angular - html

I am facing problem concerning switching background in Angular 10. I managed to implement switching background image but I would like it to be smooth.
At this moment it looks kind of like the slideshow - one image disappears and the other one appears.
My piece of code looks like this:
In typescript component I hold array of variables with urls to image.
backgroundImages = ['url(/assets/img/background.jpg)', 'url(/assets/img/background2.jpg)']
And in constructor I call refresh method which basically changes the value of variable holding reference to current background
refreshBackground(backgroundNumber: number) {
this.background = this.backgroundImages[backgroundNumber]
if (backgroundNumber == this.backgroundImages.length - 1)
backgroundNumber = 0
else
backgroundNumber++
setTimeout(() => this.refreshBackground(backgroundNumber), 10000)
}
In html this variable is set to style.background
<div class="container background" [style.background]="background">
I would appreciate any help and tips and if more details are needed, ask freely.
Michael

Related

How to create a MenuItemImage with a callback function in stead of selected image?

I have a MenuItemImage here:
auto myImage = MenuItemImage::create("image.png","image_selected.png",
CC_CALLBACK_1(HelloWorld::onImageClicked,this));
It allow me to input a image.png, which will be changed to image_selected.png on selected when I navigate between items in my menu with keyboard. However, I want to perform some actions when select it with myImage->selected(); (NOT activate it by clicking/touching or calling for myImage->activate(); function), not just a boring image_selected.png.
Now, I'm thinking about set up all of those action in:
keyBoardListener->onKeyPressed = [&](cocos2d::EventKeyboard::KeyCode keycode, Event* event)
{ // Setting up actions on KEY_RIGHT_ARROW or KEY_LEFT_ARROW pressed};
However this way makes things complicated. Therefore, I want to ask if there's any way that I could set up all of my actions as myImage being creating so I could call all of those action with a simple myImage->selected() or stop them with myImage->unselected() later?
Your attention and help is very much appreciated :D
Simply do this:
auto myImage = MenuItemImage::create("image.png", "image_selected.png", [&](Ref* ref){
//your code here
//by ref you can access "myImage" object
});
edit:
I'm not sure what are you trying to achieve. Do you want to have a few buttons in menu, which always one of the is selected and change them using arrows? (so menu navigation is like on console games).
edit2:
After watch a sample yt video I don't think you can achieve this relying only on MenuItemImage. Instead I'd create a ui::Button (if you need clicking/touching as well) or Sprite. Then I'd handle button states by myself. As for glowing frame you probably need some fancy shader or create it in photoshop and add to it an action with constantly fading out and in.

Content Transition Windows Phone

I have 2 viewboxes in my page and currently I am doing this:
ViewBox1.Visibility = Visibility.Collapsed;
ViewBox2.Visibility = Visibiltiy.Visible;
That means upon some button press, I am hiding first viewbox and showing the second one. Now, upon hiding I want a simple transition animation like viewbox1 sliding out and viewbox2 sliding in, something like this.
I have installed WPF toolkit, but can't figure this out.
Any help is highly appreciated.
Currently I have found this solution, this is actually full page transition but it works for me, I am sharing this code here:
SlideTransition transition = new SlideTransition();
transition.Mode = SlideTransitionMode.SlideLeftFadeIn;
PhoneApplicationPage page = (PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content;
ITransition trans = transition.GetTransition(page);
trans.Completed += delegate
{
trans.Stop();
};
trans.Begin();

Can you help me fixing this Slider code in ActionScript 3?

I got a dynamic Textfield called txt_nOpp setted to 1, I also got a slider, called Slider1, The slider can only assume values betweed 1 and 6. While the user sets slider value, the text should change.
I've implemented this code:
Slider1.addEventListener(SliderEvent.CHANGE, slHandler);
function slHandler(e:SliderEvent):void{
txt_nOpp.text = String(e.value);
}
Flash doesn't return any error, but the slider/text works only at value 1, the other values of the slider make the text disappear... What's wrong?
SliderEvent.CHANGE only updates when you release the slider, so try
Slider1.addEventListener(Event.ENTER_FRAME, function()
{
txt_nOpp.text = Slider1.value.toString();
});
instead.
I fixed it, it was an anti aliasing problem, just set it as device font and now works

Windows Phone 8 ApplicationBar expanded unchangable transparancy

following Code...
<!--Navigation-Bar-->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" ForegroundColor="White" IsMenuEnabled="True" BackgroundColor="#002B55">
<shell:ApplicationBarIconButton Click="B_Search_Click" IconUri="Images\Pic_Search.png" Text="Search"/>
<shell:ApplicationBarIconButton Click="B_Media_Click" IconUri="Images\Pic_Media.png" Text="Media"/>
<shell:ApplicationBarIconButton Click="B_Scan_Click" IconUri="Images\Pic_Scan.png" Text="Scanner"/>
<shell:ApplicationBarIconButton Click="B_Charts_Click" IconUri="Images\Pic_Charts.png" Text="Charts"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Click="B_Logout_Click" Text="Logout"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
gives me following ApplicationBar...
http://s14.directupload.net/file/d/3341/4xiadbvz_jpg.htm
(Solid background when expanded)
BUT if I create the AppBar in CodeBehind like this...
private void ResetApplicationBar()
{
ApplicationBar = new ApplicationBar();
ApplicationBar.BackgroundColor = Color.FromArgb(150, 0, 43, 85);;
ApplicationBar.ForegroundColor = Colors.White;
ApplicationBar.Opacity = 1;
ApplicationBarIconButton B_Search = new ApplicationBarIconButton();
B_Search.IconUri = new Uri("/Images/Pic_Search.png", UriKind.Relative);
B_Search.Text = "search";
ApplicationBar.Buttons.Add(B_Search);
B_Search.Click += new EventHandler(B_Search_Click);
(more Buttons...)
then I get that misterios unchangable Transparency...
http://s1.directupload.net/file/d/3341/zjo57e37_jpg.htm
(Half-Transparent when expanded)
How can I change the Background to solid???
-Yes I have mostly overwritten the theme
-Changing global colors doesnt work
-changing background/foreground doesnt work
-changing opacity doesnt work...
I need to generate it from code behind because im changing it dynamically in one window
(or is it possible to define multiple AppBars in markup?)
Thanks in advance!
Please try this one
ApplicationBar.BackgroundColor = Color.FromArgb(52,0,2,181);
ApplicationBar.ForegroundColor = Colors.White;
You will get the same color in designer page by this way.
This (52,0,2,181) is the conversion value of #002B55
On a fresh project, everything seems fine, here.
"- changing background/foreground doesnt work
- changing opacity doesnt work..."
Using the Application Bar sample, you provided in XAML, but with Opacity=0.5, I get this :
After I click the "Change Color" button, which does ApplicationBar.Opacity = 1;, I get this result :
(The background image is slightly moved up, because in first case we provided an opacity and in the second there was none explicitly specified and it seems the app bar didn't layered over the image, but to fix this you can set an Opacity=0.999, close to 1).
It must have something to do with all the theme overwriting you have done or some customization you attempted.
If this isn't quite helpful, provide me more details and I'll try to help as I can.
Thank you very much for effort, but changing opacity didnt to 0.999 didnt help either.
I found a solution!! And its quite simple :)
I Just take the old bar instead of creating a new one:
//Old Code
ApplicationBar = new ApplicationBar();
//New Code
ApplicationBar.Buttons.Clear();
ApplicationBar.MenuItems.Clear();
Hope it helps someone!

no "current_page_item" class being added to top level nav item

If you go to www.lindysez.com and click on the top level navigation links, you'll notice that position presence is indicated by a slightly darker background (same as hover state). This works for each of the links EXCEPT "Tips & Techniques".
If I look under the hood, I noticed that the "current_page_item" class isn't being added to the parent of the "Tips & Techniques" menu item when you go to http://www.lindysez.com/tips
Also, curiously enough, when on the tips page, the parent of the "Blog" navigation item gets the class "current_page_parent", which is neither expected nor desired. This is harmless from a UI standpoint, but probably an indication what the underlying problem might be.
Anyone know why the "Tips & Techniques" menu item isn't getting the "current_page_item" class once selected?
Update: Directed #user2019515's comment below
Thanks for the nudge in this direction, it does seem like I could create a workaround that would fix this. Couple things however.
This treats the symptom of the problem rather than the root. I'd like to figure out how to get wp to just add the "current_page_item" class natively. Any idea what's causing this? I think it may also be related to another problem I'm having which involves "tips" not showing in the RSS feed. I posted another question about that, but haven't seen any answers...
https://stackoverflow.com/questions/15980846/custom-post-type-not-showing-up-in-wordpress-rss-feed
Even as a workaround, I'd rather try to avoid a solution that relies on hard coded "menu-item-##". My development and production servers both have different ID#'s. I know I can account for this, but I hope there's a better, scalable workaround.
The code you provided didn't work for me, not that I can find any fault in it, nor are there any errors. Seems like it should work, but just doesn't. I even tried creating a very simple version that would add a class to all the items, but this too isn't executing. Here's that code.
function add_class_to_wp_nav_menu($classes, $item)
{
$classes[] = 'classy-class';
return $classes;
}
add_filter('nav_menu_css_class', 'add_class_to_wp_nav_menu', 10, 2);
Thanks so much for your help!
The Tips page is a post archive page, it shows posts rather than a normal page that's why the blog was being highlighted. You can easily fix this issue by adding the following custom CSS to your style.css file.
.post-type-archive-tips .menu-item-23{
background:url(images/nav-hover.png) repeat-x;
}
You'll need to loop over your menu, by default the current page class is added to the blog page because in the end the custom posts.
//Change current_page_parent for custom post type
function remove_parent_classes($class)
{
// check for current page classes, return false if they exist.
return ($class == 'current_page_item' || $class == 'current_page_parent' || $class == 'current_page_ancestor' || $class == 'current-menu-item') ? FALSE : TRUE;
}
function add_class_to_wp_nav_menu($classes)
{
switch (get_post_type()) {
case 'portfolio':
// we're viewing a custom post type, so remove the 'current_page_xxx and current-menu-item' from all menu items.
$classes = array_filter($classes, "remove_parent_classes");
// add the current page class to a specific menu item (replace ###).
if (in_array('menu-item-14', $classes)) {
$classes[] = 'current_page_parent';
}
break;
case 'tips':
// we're viewing a custom post type, so remove the 'current_page_xxx and current-menu-item' from all menu items.
$classes = array_filter($classes, "remove_parent_classes");
// add the current page class to a specific menu item (replace ###).
if (in_array('menu-item-23', $classes)) {
$classes[] = 'current_page_parent';
}
break;
}
return $classes;
}
add_filter('nav_menu_css_class', 'add_class_to_wp_nav_menu');
There's just one custom post type in the function, but I'm sure you can figure out how to add more. Got any questions, feel free to leave a comment! :)