title: "Hover Animation Control" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Editor Controls - Src - Repos
Hover Animation Control
Elementor hover animation control displays a select box field based on the Hover.css library. The control allows to set an hover animation effect for an item.
The control is defined in Control_Hover_Animation class which extends Base_Data_Control class.
When using this control, the type should be set to \Elementor\Controls_Manager::HOVER_ANIMATION constant.
参数
| 名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
type |
string |
hover_animation | 控件的类型。 |
label |
string |
显示在字段上方的标签。 | |
description |
string |
显示在字段下方的描述。 | |
show_label |
bool |
true | 是否显示标签。 |
label_block |
bool |
true | 是否在单独一行显示标签。 |
separator |
string |
default | 设置控件分隔符的位置。可用值为 default、before 和 after。default 将隐藏分隔符,除非控件类型有特定的分隔符设置。before / after 会将分隔符定位在控件之前/之后。 |
default |
string |
字段的默认值。 |
Return Value
(string) The selected hover animation class.
Usage
```php {14-20,29-33,35-37,43-52}
start_controls_section( 'style_section', [ 'label' => esc_html__( 'Style', 'textdomain' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'hover_animation', [ 'label' => esc_html__( 'Hover Animation', 'textdomain' ), 'type' => \Elementor\Controls_Manager::HOVER_ANIMATION, ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); $elementClass = 'container'; if ( $settings['hover_animation'] ) { $elementClass .= ' elementor-animation-' . $settings['hover_animation']; } $this->add_render_attribute( 'wrapper', 'class', $elementClass ); ?> <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
...
</div>
<?php
}
protected function content_template(): void {
?>
<#
const elementClass = 'container';
if ( '' !== settings.hover_animation ) {
elementClass += ' elementor-animation-' + settings.hover_animation;
}
view.addRenderAttribute( 'wrapper', { 'class': elementClass } );
#>
<div {{{ view.getRenderAttributeString( 'wrapper' ) }}}>
...
</div>
<?php
}
} ```